Purpose
TO_BLOB() converts LONG RAW and RAW values to BLOB values.
Syntax
TO_BLOB( raw_value )
Parameters
raw_value is of the LONG RAW or RAW data type.
Return type
The return type is BLOB.
Examples
Create a table named tbl_raw, add a column named COL_RAW, set the column type to RAW and column length to 16 bytes, and insert data.
CREATE TABLE tbl_raw (COL_RAW RAW(16));
-- Insert a row of data into the table, where the value of the `COL_RAW` column is `0ABC`.
-- In the `RAW` type, a string is interpreted as hexadecimal data.
-- Therefore, the `'0ABC'` value here is stored in the binary format and occupies two bytes: 0A (hexadecimal format) and BC (hexadecimal format).
INSERT INTO tbl_raw (COL_RAW) VALUES ('0ABC');
-- Insert another row of data, where the value of the `COL_RAW` column is `0123456789ABCDEF`. The value is converted and stored as binary data of eight bytes.
-- The eight binary bytes are: 01, 23, 45, 67, 89, AB, CD, and EF.
INSERT INTO tbl_raw (COL_RAW) VALUES ('0123456789ABCDEF');
Execute the following SQL statement to convert RAW values in the tbl_raw table into BLOB values and return the corresponding byte length:
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