How To Convert A VARCHAR2 Column To A CLOB Column PDF
How To Convert A VARCHAR2 Column To A CLOB Column PDF
How To Convert A VARCHAR2 Column To A CLOB Column PDF
754542.1]
Modified:Mar
1, 2013
Type:HOWTO
Status:PUBLISHED
Priority:3
Comments (0)
In this Document
Goal
Solution
Applies to:
Oracle Server - Enterprise Edition - Version: 9.2.0.1 and later [Release: 9.2 and later ]
Information in this document applies to any platform.
Goal
The following SQL script demonstrates how to convert a VARCHAR2 column to a CLOB
column.
Solution
Run the following script from SQL*Plus:
1 row created.
SQL>
SQL> -- Validate the data has been inserted properly
SQL> SELECT * FROM varchar_to_clob;
COL1 COL2
---------- -----------------------1 This is a test item 1
2 This is a test item 2
SQL>
SQL> -- Add a new CLOB column to the table
SQL> ALTER TABLE varchar_to_clob ADD col3 CLOB;
Table altered.
SQL>
SQL> -- Verify the change
SQL> DESC varchar_to_clob
Name
Null? Type
----------------------------------------- -------- ---------------------------COL1
NUMBER
COL2
VARCHAR2(4000)
COL3
CLOB
SQL>
SQL> -- Perform the following update statement which converts and copies
SQL> -- the VARCHAR2 data into the newly created CLOB column
SQL> UPDATE varchar_to_clob SET col3 = TO_CLOB(col2);
2 rows updated.
SQL>
SQL> -- Verify the change
SQL> SELECT * FROM varchar_to_clob;
COL1 COL2
COL3
---------- ------------------------ -----------------------1 This is a test item 1 This is a test item 1
2 This is a test item 2 This is a test item 2
SQL>
SQL> -- Drop the VARCHAR2 column as it is no longer needed
SQL> ALTER TABLE varchar_to_clob DROP COLUMN col2;
Table altered.
SQL>
SQL> -- Change the name of col3 to col2
SQL> ALTER TABLE varchar_to_clob RENAME COLUMN col3 TO col2;
Table altered.
SQL>
SQL> -- Verify the change
SQL> DESC varchar_to_clob
Name
Null? Type
----------------------------------------- -------- ---------------------------COL1
NUMBER
COL2
CLOB
SQL>
SQL> -- Validate the date has been converted properly
SQL> SELECT * FROM varchar_to_clob;
COL1 COL2
---------- -----------------------1 This is a test item 1
2 This is a test item 2
SQL>