---
title: "LOB functions"
description: "CoraDB functions for BLOB and CLOB values: CHAR_TO_CLOB, CLOB_TO_CHAR, CLOB_LENGTH, BLOB_FROM_FILE and more, with examples."
url: "https://www.coradb.ai/manual/sql/function/lob_fn.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/function/lob_fn.md"
product: "CoraDB"
version: "1.0"
keywords: "lob functions, blob, clob, char_to_clob, clob_to_char, clob_length, blob_length, blob_to_bit, bit_to_blob, clob_from_file, blob_from_file, coradb"
---

# 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](https://www.coradb.ai/manual/sql/datatype.html).

The examples use a scratch table for product documents:

```sql
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

```text
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

```text
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

```text
CLOB_LENGTH(clob)
BLOB_LENGTH(blob)
```

Return the size of a LOB value, in bytes. **Return type:** BIGINT.


## CLOB_FROM_FILE, BLOB_FROM_FILE

```text
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.

```sql
INSERT INTO product_doc VALUES (335, CLOB_FROM_FILE('file:/data/manuals/335.txt'), BLOB_FROM_FILE('/data/thumbnails/335.png'));
```
