This Oracle tutorial explains how to use the Oracle/PLSQL RAWTOHEX function with syntax and examples.
The Oracle/PLSQL RAWTOHEX function converts a raw value into a hexadecimal value. One of our viewers says that this function comes in handy to move a varchar value to a blob field.
The syntax for the RAWTOHEX function in Oracle/PLSQL is:
The raw value to convert to a hexademical value.
The RAWTOHEX function returns a string value.
This function works differently when used as a PLSQL built-in function as opposed to running it in SQL. As a PLSQL function, the RAWTOHEX function may perform an implicit conversion before converting to a hexadecimal value. This may result in a different value being returned by this function between PLSQL and SQL.
For example, if you ran the following:
The following would be output as the result:
The reason for the difference is that PLSQL is doing an implicit conversion of 'AB' into a RAW (treats 'AB' as a single byte equal to CHR(171)). A RAWTOHEX on that returns the string 'AB'.
Whereas, SQL is not doing that implicit conversion. 'AB' is 2 byte RAW already and a RAWTOHEX of that retuns 4142.
The RAWTOHEX function can be used in the following versions of Oracle/PLSQL:
Let's look at some Oracle RAWTOHEX function examples and explore how to use the RAWTOHEX function in Oracle/PLSQL.
For example: