Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change column varchar to clob in oracle

I have a column details designed as varchar in oracle DB, this DB is being used now for customers and some rows already have data stored.

Now I want to change the column details to a Clob column. What is a smart way to accomplish this?

like image 613
Whtisop Avatar asked Jul 27 '11 04:07

Whtisop


People also ask

Can we change varchar to CLOB in Oracle?

But that is not the case with changing VARCHAR2 to CLOB. The difference between the 2 types is that in VARCHAR2 you have to specify the length of the stored string and that length is limited to 4000 characters while CLOB can store up to 128 terabytes of character data in the database.


2 Answers

(as the previous answer) and here's the code:

ALTER TABLE atable  ADD (tmpdetails  CLOB);  UPDATE atable SET tmpdetails=details; COMMIT;  ALTER TABLE atable DROP COLUMN details;  ALTER TABLE atable RENAME COLUMN tmpdetails TO details; 
like image 110
Kevin Burton Avatar answered Sep 23 '22 02:09

Kevin Burton


  1. Add a clob column to the table
  2. update clob column with values from varchar column
  3. drop varchar column
  4. rename clob column to varchar columns name
like image 29
Rene Avatar answered Sep 23 '22 02:09

Rene