rawtohex
1. RAWTOHEX Function
=======rawtohex
1. RAWTOHEX Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe RAWTOHEX function in H2 database is used to convert a binary value to its hexadecimal representation.
2. Syntax
The syntax for the RAWTOHEX function in H2 database is as follows:
RAWTOHEX(binary)
Arguments
binary
: The binary value that needs to be converted to hexadecimal. It should be of type BINARY or VARBINARY.
Return
- The RAWTOHEX function returns a string representing the hexadecimal value of the input binary.
3. Notes
- The RAWTOHEX function in H2 database is specific to binary values. If you want to convert non-binary values to hexadecimal, you can use other functions like
HEX
orTO_HEXADECIMAL
. - If the input binary is
NULL
, the RAWTOHEX function will returnNULL
. - Ensure that you are passing the correct data type as the argument for the RAWTOHEX function to avoid errors.
4. Examples
Here are a few examples demonstrating the usage of the RAWTOHEX function in H2 database:
Example 1 - Converting a binary value to hexadecimal:
SELECT RAWTOHEX(X'48656C6C6F') AS hex_value;
Output:
hex_value
---------
48656C6C6F
Example 2 - Converting binary values stored in a table to hexadecimal:
CREATE TABLE binary_data (
id INT PRIMARY KEY,
data VARBINARY
);
INSERT INTO binary_data VALUES (1, X'FF'), (2, X'C0DE');
SELECT id, data, RAWTOHEX(data) AS hex_value
FROM binary_data;
Output:
id | data | hex_value
---+--------+----------
1 | FF | 46
2 | C0DE | 43D0DE
5. Related Functions
- HEX - Convert a numeric value to its hexadecimal representation.
- TO_HEXADECIMAL - Convert a string value to its hexadecimal representation.