Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

database - Oracle: Changing VARCHAR2 column to CLOB

I have an encountered an issue where the data I was trying to store in my varchar2(4000) column was too big, so I wish to change the column to one more suitable for storing large amounts of textual data. Specifically, a serialized array.

  1. Firstly, is CLOB the best data type for me to use for this purpose? Is there a more appropriate data type?

  2. Secondly, when I try to alter the column using the usual snyntax:

    ALTER TABLE table MODIFY column CLOB
    

    I get the following error: ORA-22858: invalid alteration of datatype

    What's the most straightforward way to alter this table without losing any data?

question from:https://stackoverflow.com/questions/13402510/oracle-changing-varchar2-column-to-clob

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The most straightforward way, given that the operation of moving from a varchar column to a CLOB is disallowed, would be to create a new column and move the data from the old column to the new column:

ALTER TABLE some_table ADD (foo CLOB);
UPDATE some_table SET foo = old_column;
ALTER TABLE some_table DROP COLUMN old_column;
ALTER TABLE some_table RENAME COLUMN foo TO old_column;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...