Purpose
This function converts NCLOB values in LOB columns or other strings to CLOB values.
Syntax
TO_CLOB(lob_column | char)
Parameters
| Parameter | Description |
|---|---|
| lob_column | A NCLOB value in a LOB column or other string. |
| char | A value of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB type. |
Return type
CLOB
Examples
Create the tbl_nclob table.
-- Create a new table named tbl_nclob
CREATE TABLE tbl_nclob (
-- Add a column named COL1 with the NUMBER data type and a maximum precision of 38
COL1 NUMBER(38),
-- Add a column named COL_CHAR with the VARCHAR2 data type and a maximum length of 100 characters
COL_CHAR VARCHAR2(100),
-- Add a column named COL_CLOB with the CLOB data type for storing large text data
COL_CLOB CLOB
);
Convert a VARCHAR2 value to a CLOB value and insert it into a 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