Purpose
This function converts LONG RAW and RAW values to BLOB values.
Syntax
TO_BLOB( raw_value )
Parameters
The raw_value parameter is a value of the LONG RAW or RAW type.
Return type
Returns the BLOB type.
Examples
In the following example, we create a tbl_raw table and add a COL_RAW column with a RAW data type and a length of 16 bytes, then insert data.
CREATE TABLE tbl_raw (COL_RAW RAW(16));
-- Insert a row into the table with the value '0ABC' for the COL_RAW column
-- In RAW type, the string is interpreted as hexadecimal data
-- Therefore, '0ABC' will be stored in binary form, occupying 2 bytes: 0A (hexadecimal) and BC (hexadecimal)
INSERT INTO tbl_raw (COL_RAW) VALUES ('0ABC');
-- Insert another row with the value '0123456789ABCDEF' for the COL_RAW column
-- This will be converted to binary data and stored as 8 bytes: 01, 23, 45, 67, 89, AB, CD, EF
INSERT INTO tbl_raw (COL_RAW) VALUES ('0123456789ABCDEF');
The following SQL statement will convert the RAW values in the tbl_raw table to BLOB values and return the corresponding byte lengths.
obclient> SELECT COL_RAW,LENGTHB(COL_RAW) "LENGTHB_RAW",LENGTHB(TO_BLOB(COL_RAW)) "LENGTHB_BLOB"
FROM tbl_raw;
+------------------+-------------+--------------+
| COL_RAW | LENGTHB_RAW | LENGTHB_BLOB |
+------------------+-------------+--------------+
| 0ABC | 4 | 2 |
| 0123456789ABCDEF | 16 | 8 |
+------------------+-------------+--------------+
2 rows in set