LOB functions
LOB functions convert values to and from the large object types BLOB (binary data) and CLOB (character data), read files into LOBs, and return LOB sizes. For how LOB values are stored, see BLOB/CLOB.
The examples use a scratch table for product documents:
CREATE TABLE product_doc (product_id INT PRIMARY KEY, manual CLOB, thumbnail BLOB);
INSERT INTO product_doc VALUES (1795, CHAR_TO_CLOB('Machine wash cold. Do not bleach.'), BIT_TO_BLOB(X'89504E47'));INSERT INTO product_doc VALUES (123, 'Hand wash only.', CHAR_TO_BLOB('icon')); -- strings are converted to CLOB automatically
SELECT product_id, CLOB_LENGTH(manual), CLOB_TO_CHAR(manual), BLOB_LENGTH(thumbnail), BLOB_TO_BIT(thumbnail)FROM product_doc ORDER BY product_id;| product_id | clob_length(manual) | clob_to_char(manual) | blob_length(thumbnail) | blob_to_bit(thumbnail) |
|---|---|---|---|---|
| 123 | 15 | Hand wash only. | 4 | 0x69636f6e |
| 1795 | 33 | Machine wash cold. Do not bleach. | 4 | 0x89504e47 |
CHAR_TO_CLOB, CLOB_TO_CHAR
Section titled “CHAR_TO_CLOB, CLOB_TO_CHAR”CHAR_TO_CLOB(string)CLOB_TO_CHAR(clob [USING charset])CHAR_TO_CLOB converts a CHAR or VARCHAR value to CLOB. CLOB_TO_CHAR converts a CLOB value to VARCHAR; USING names the character set of the result (utf8, euckr or iso88591).
CHAR_TO_BLOB, BIT_TO_BLOB, BLOB_TO_BIT
Section titled “CHAR_TO_BLOB, BIT_TO_BLOB, BLOB_TO_BIT”CHAR_TO_BLOB(string)BIT_TO_BLOB(bit_value)BLOB_TO_BIT(blob)CHAR_TO_BLOB stores the bytes of a string as a BLOB; BIT_TO_BLOB converts a BIT or BIT VARYING value to BLOB; BLOB_TO_BIT converts a BLOB back to BIT VARYING.
CLOB_LENGTH, BLOB_LENGTH
Section titled “CLOB_LENGTH, BLOB_LENGTH”CLOB_LENGTH(clob)BLOB_LENGTH(blob)Return the size of a LOB value, in bytes. Return type: BIGINT.
CLOB_FROM_FILE, BLOB_FROM_FILE
Section titled “CLOB_FROM_FILE, BLOB_FROM_FILE”CLOB_FROM_FILE(file_path)BLOB_FROM_FILE(file_path)Read a file and return its contents as a CLOB or BLOB. file_path is a VARCHAR: a path on the machine where the server-side client process runs (the broker's CAS process, or corasql), optionally prefixed with file:. A relative path starts from that process's current working directory. Statements that call these functions are not stored in the query plan cache.
INSERT INTO product_doc VALUES (335, CLOB_FROM_FILE('file:/data/manuals/335.txt'), BLOB_FROM_FILE('/data/thumbnails/335.png'));