Purpose
TO_CLOB() converts NCLOB values in a LOB column or other strings to CLOB values.
Syntax
TO_CLOB(lob_column | char)
Parameters
| Parameter | Description |
|---|---|
| lob_column | A LOB column to be converted to the CLOB type. |
| char | Values of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB type to be converted to the CLOB type. |
Return type
The return type is CLOB.
Examples
Create a table named tbl_nclob.
-- Create a table named `tbl_nclob`.
CREATE TABLE tbl_nclob (
-- Add a column named `COL1`. Set the column type to `NUMBER` and maximum precision to 38 digits.
COL1 NUMBER(38),
-- Add a column named `COL_CHAR`. Set the column type to `VARCHAR2` and maximum length to 100 characters.
COL_CHAR VARCHAR2(100),
-- Add a column named `COL_CLOB`. Set the column type to `CLOB` for storing long text data.
COL_CLOB CLOB
);
Convert VARCHAR2 values into CLOB values and insert the values into the CLOB column.
obclient> DESC tbl_nclob;
+----------+---------------+------+-----+---------+-------+
| FIELD | TYPE | NULL | KEY | DEFAULT | EXTRA |
+----------+---------------+------+-----+---------+-------+
| COL1 | NUMBER(38) | YES | NULL | NULL | NULL |
| COL_CHAR | VARCHAR2(100) | YES | NULL | NULL | NULL |
| COL_CLOB | CLOB | YES | NULL | NULL | NULL |
+----------+---------------+------+-----+---------+-------+
3 rows in set
obclient> UPDATE tbl_nclob SET col_clob = TO_CLOB (col_char);
Query OK, 1 row affected
Rows matched: 1 Changed: 1 Warnings: 0