In Oracle Database, the RAWTONHEX() function converts a raw value to hexadecimal.
It’s similar to the RAWTOHEX() function, except that its value is always returned in the national character set.
Syntax
The syntax goes like this:
RAWTONHEX(raw)
Example
Here’s an example:
SELECT
RAWTONHEX(HEXTORAW('f9')) AS "Result",
DUMP(RAWTONHEX(HEXTORAW('f9'))) AS "Dump"
FROM DUAL;
Result:
Result Dump _________ _________________________ F9 Typ=1 Len=4: 0,70,0,57
Here, I used the HEXTORAW() function to convert a hexadecimal string to RAW, then used RAWTONHEX() to convert it back. The output of the DUMP() function shows that the returned data type is of type 1.
Null Argument
If the argument is null, the result is null:
SET NULL 'null';
SELECT RAWTONHEX(null)
FROM DUAL;
Result:
null
By default, SQLcl and SQL*Plus return a blank space whenever a null value occurs as a result of a SQL SELECT statement.
However, you can use SET NULL to specify a different string to be returned. Here I specified that the string null should be returned.
Invalid Argument Count
Calling RAWTONHEX() without any arguments results in an error:
SELECT RAWTONHEX()
FROM DUAL;
Result:
SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments"
And passing too many arguments also results in an error:
SELECT RAWTONHEX('a', 'b')
FROM DUAL;
Result:
SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments"