How to change a dataype CLOB TO VARCHAR2(sql)

社会主义新天地 提交于 2019-12-10 02:13:56

问题


Table: customers

ID      NAME             DATATYPE
NUMBER  VARCHAR2(100)    CLOB

I want to change the DATA column from CLOB to `VARCHAR2(1000)

I have try ALTER TABLE customers MODIFY DATA VARCHAR2 (1000) also

ALTER TABLE customers MODIFY (DATA VARCHAR2 (1000))

also

alter table customers  modify
(data VARCHAR2(4000))

those normally works if the datatype is not a clob but I am getting a ORA-22859 because I am using oracle toad/apex.


回答1:


You may try this:

  1. Add a new column as varchar2

    alter table my_table add (new_column varchar2(1000));

  2. UPDATE CLOB name to varchar2 column;

    update my_table set new_column=dbms_lob.substr(old_column,1000,1);

After testing your data:

  1. DROP CLOB column

    alter table my_table drop column old_column

  2. Rename varchar2 column to CLOB column name

    alter table my_table rename column new_column to old_column



来源:https://stackoverflow.com/questions/19841947/how-to-change-a-dataype-clob-to-varchar2sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!