oracle 如何将数据类型 CLOB 更改为 VARCHAR2(sql)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19841947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change a dataype CLOB TO VARCHAR2(sql)
提问by PHPnoob
Table: customers
表:客户
ID NAME DATATYPE
NUMBER VARCHAR2(100) CLOB
I want to change the DATA
column from CLOB
to `VARCHAR2(1000)
我想将DATA
列从更改CLOB
为 `VARCHAR2(1000)
I have try ALTER TABLE customers MODIFY DATA VARCHAR2 (1000)
also
我尝试ALTER TABLE customers MODIFY DATA VARCHAR2 (1000)
也
ALTER TABLE customers MODIFY (DATA VARCHAR2 (1000))
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.
如果数据类型不是clob,这些通常有效,但我得到一个,ORA-22859
因为我使用的是oracle toad/apex。
回答by Rahul Tripathi
You may try this:
你可以试试这个:
Add a new column as varchar2
alter table my_table add (new_column varchar2(1000));
UPDATE CLOB name to varchar2 column;
update my_table set new_column=dbms_lob.substr(old_column,1000,1);
添加一个新列作为 varchar2
alter table my_table add (new_column varchar2(1000));
将 CLOB 名称更新为 varchar2 列;
update my_table set new_column=dbms_lob.substr(old_column,1000,1);
After testing your data:
经过测试数据:
DROP CLOB column
alter table my_table drop column old_column
Rename varchar2 column to CLOB column name
alter table my_table rename column new_column to old_column
删除 CLOB 列
alter table my_table drop column old_column
将 varchar2 列重命名为 CLOB 列名
alter table my_table rename column new_column to old_column