Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
The iQuery.fromHex() UDF inspects converts each pair of input characters (which must represent a hexadecimal value) into a single character/byte. Therefore a 16-byte input value is converted into an 8-byte result.
This is the complement function to the built-in SQL HEX() UDF which "unfolds" one byte into two hex bytes.
UDF | Return Type | Description |
fromHex | varchar(4096) | Convert input from hexadecimal to character. |
iQuery.fromHex( input string varchar(8192) )
The input-string parameter can be any textual data that contains hexadecimal pairs (2 characters of 0-1 or A-F) that are folded into a single character and then returned.
values hex('12345XYZ') into :output;
-- OUTPUT now contains: F1F2F3F4F5E7E8E9
values iQuery.fromHex(:output) into :data;
-- DATA now contains '12345XYZ'
values iQuery.fromHex(hex('12345XYZ'));
-- The output from this SQL stmt is: 12345XYZ