简体   繁体   中英

cast a hex value into a char oracle

In teradata we have the concept of casting a hex into a char like the following:

select cast(X'0000' AS CHAR(16)) from something;

What's the equivalent Oracle representation of this X''

Could it be UNISTR?

To convert a series of hexadecimal digits to a number you can use the TO_NUMBER function with the 'X' mask character, as in:

SELECT TO_NUMBER('12AB', 'XXXX') FROM dual;

This produces the (decimal) result 4779.

If you want to go the other way, ie convert a number to its hexadecimal representation, you can use the TO_CHAR function:

SELECT TO_CHAR(4779, 'XXXXXXXXXXXXXXXX') FROM dual;

which produces the result ' 12AB' . Note that because the TO_CHAR function leaves room for a sign ( + or - ) the returned string is actually 17 characters wide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM