on 07-22-2022 11:01 AM
I wish to Base64-decode data in SAP ASE using SQL. I can do the inverse (Base64-encode binary data) using the following approach:
-- PREPARATION: get HEX bytes of ASCII string as test input for Base64-encode
select bintostr(convert(varbinary(16384), 'test'))
-- returns 74657374
-- WORKS: Base64 from HEX
select xmlextract('//C1/text()', c_xml) from (select (select cast(strtobin('74657374') as varbinary(16384)) for xml option 'binary=base64')) t(c_xml)
-- returns dGVzdA==
However, the following approach of using the XMLTABLE function with an explicit data conversion back to VARBINARY doesn't decode the Base64-encoded data, but instead returns the hex-bytes of the Base64 characters:
-- FAILS: HEX from Base64
select c_bin from xmltable('/rows/row' passing '<rows><row><col>dGVzdA==</col></row></rows>' columns col varbinary(16384)) t(c_bin)
-- returns 0x6447567a64413d3d instead of 0x74657374
Is there any fix to the last query or alternative approach to get back the original binary value 0x74657374?
User | Count |
---|---|
75 | |
8 | |
8 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.