2

I have database and some text fields are CLOB type, I need to change most of these into VARCHAR2.

Have tried to do that using SQL Developer tool, by clicking edit on table, but get error like this one:

The following SQL statement failed:

ALTER TABLE TBL_PEOPLE   MODIFY (PERSON VARCHAR2(150) )

Want to ask, how can this change be done

2 Answers 2

2

You can't, directly. The code you tried will have got an `ORA-22859, presumably. (It's helpful to show the actual errors you get, of course).

You'll need to add a new varchar2 column; copy the data across - or a substring of it if it might be larger than the new column you're creating; drop the clob column. You can rename the columns so it looks fairly transparent.

As in this SQL Fiddle:

alter table tbl_people rename column person to clob_person;

alter table tbl_people add (person varchar2(150));

update tbl_people set person = clob_person;

alter table tbl_people drop column clob_person;

Obviously don't drop the old column until you're sure the data has copied without errors. Also take into account any constraints, indexes, etc. that might exist in the old column; they will need to be recreated. And anything that references the old column will have been invalidated - generally procedures will recompile themselves on next use.

So be careful, test it first, and plan some down time.

0
ALTER TABLE tablename ADD (FIELD_LIST_TEMP VARCHAR2);  
UPDATE tablename SET FIELD_LIST_TEMP = FIELD_LIST;
ALTER TABLE tablename DROP COLUMN FIELD_LIST;
ALTER TABLE tablename RENAME COLUMN FIELD_LIST_TEMP TO FIELD_LIST;

Here FIELD_LIST existing column which is defined it as CLOB. With above query it will change from CLOB to VARCHAR2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.