Oracle RAWTONHEX() Function

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

Unlike RAWTOHEX(), the return value of RAWTONHEX() is always in the national character set.

Oracle RAWTONHEX() Syntax

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

RAWTONHEX(raw)

Parameters

raw

Required. It can be any scalar data type (excluding LONG, LONG RAW, CLOB, NCLOB, BLOB, or BFILE). If it is not of RAW data type, this function will convert the parameter value represented by some data bytes to a RAW value having the same number of data bytes. The data itself is not modified in any way, but the data type is converted back to the RAW data type.

Return Value

The Oracle RAWTONHEX() function returns a VARCHAR2 value containing the hexadecimal representation of the bytes composing the raw value. Each byte is represented by two hexadecimal digits.

If any parameter is NULL, RAWTONHEX() will return NULL.

Oracle RAWTONHEX() Examples

Here are some examples showing the usage of the Oracle RAWTONHEX() function.

Basic Usage

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

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

输出:

RAWTONHEX(HEXTORAW('87EA'))
______________________________
87EA

NULL Parameter

If any parameter is NULL, RAWTONHEX() will return NULL.

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

输出:

RAWTONHEX(NULL)
__________________
NULL

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

Conclusion

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