[#SOL-138] Convert hexadecimal values to a decimal

advertisement
[SOL-138] Convert hexadecimal values to a decimal Created: 18.08.2014
Updated:
24.07.2015 Resolved: 24.07.2015
Status:
Project:
Component/s:
Affects
Version/s:
Fix Version/s:
Published
Solution Center
EXASolution
None
Type:
Reporter:
Labels:
How To
Captain EXASOL
None
Solution:
There is currently no builtin solution for this yet, but it's part of our roadmap
(EXASOL-1162).
None
Assignee:
Captain EXASOL
Until then, you have to do conversions manually, for example using a scalar
pl/SQL function like this:
CREATE OR REPLACE FUNCTION hex2dec (hexnum IN VARCHAR(30))
RETURN DECIMAL(36,0)
IS
i INTEGER;
digits INTEGER;
res DECIMAL(36,0);
current_digit CHAR(1);
current_digit_dec DECIMAL(2,0);
BEGIN
res := 0;
digits := LENGTH(hexnum);
FOR i IN 1..digits LOOP
current_digit := lower(SUBSTR(hexnum, i, 1));
IF current_digit IN ('a','b','c','d','e','f')
THEN
current_digit_dec :=
ASCII(current_digit) - ASCII('a') + 10;
ELSE
current_digit_dec :=
TO_NUMBER(current_digit);
END IF;
res := (res * 16) + current_digit_dec;
END LOOP;
RETURN res;
END
/
Please note that EXASolution's decimal type is limited to 36 signed digits,
which makes this smaller than 128 bit, in fact even a little bit smaller than
the 30 hex-chars (15 data bytes) we allow in the above script.
SQL - Data types
Category 1:
Generated at Wed Feb 10 04:29:23 CET 2016 using JIRA 6.4.12#64027sha1:e3691cc1283c0f3cef6d65d3ea82d47743692b57.
Download