Oracle RAWTOHEX() Function

Oracle RAWTOHEX() is a built-in function that converts a raw value to a character value that contains its hexadecimal representation.

RAWTOHEX() is the opposite of HEXTORAW().

Syntax of Oracle RAWTOHEX()

Here is the syntax of the Oracle RAWTOHEX() function:

RAWTOHEX(raw)

Parameters

raw

Required. It can be any scalar data type except LONG, LONG RAW, CLOB, NCLOB, BLOB, or BFILE. If it is not of the RAW data type, this function converts the parameter value, which is represented using some data bytes, to a RAW value with the same number of data bytes. The data itself is not modified in any way, but the data type is converted to the RAW data type.

Return Value

The Oracle RAWTOHEX() function returns a VARCHAR2 value that contains the hexadecimal representation of the bytes that make up the raw value. Each byte is represented by two hexadecimal digits.

If either parameter is NULL, RAWTOHEX() returns NULL.

Examples of Oracle RAWTOHEX()

Here are some examples that demonstrate the usage of the Oracle RAWTOHEX() function.

Basic Usage

This statement converts the raw value 87EA to a string:

SELECT
    RAWTOHEX(HEXTORAW('87EA'))
FROM dual;

输出:

RAWTOHEX(HEXTORAW('87EA'))
_____________________________
87EA

NULL Parameter

If either parameter is NULL, RAWTOHEX() returns NULL.

SET NULL 'NULL';
SELECT
    RAWTOHEX(NULL)
FROM dual;

输出:

RAWTOHEX(NULL)
_________________
NULL

In this example, we use the SET NULL 'NULL'; statement to display the NULL value as the string 'NULL'.

Conclusion

Oracle RAWTOHEX() is a built-in function that converts a raw value to a character value that contains its hexadecimal representation.