In Oracle Database, the RAWTOHEX() function converts a raw value to hexadecimal.
Syntax
The syntax goes like this:
RAWTOHEX(raw)
Where raw can be any scalar data type other than LONG, LONG RAW, CLOB, NCLOB, BLOB, or BFILE.
If the argument is of a data type other than RAW, then the function converts the argument into a RAW value with the same number of data bytes.
Example
Here’s an example:
SELECT RAWTOHEX(HEXTORAW('374a5cfe')) FROM DUAL;
Result:
374A5CFE
Here, I used the HEXTORAW() function to convert the hexadecimal string to RAW, then used RAWTOHEX() to convert it back.
Null Argument
If the argument is null, the result is null:
SET NULL 'null';
SELECT RAWTOHEX(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 RAWTOHEX() without any arguments results in an error:
SELECT RAWTOHEX()
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 RAWTOHEX('a', 'b')
FROM DUAL;
Result:
SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments"