SQL 如何在oracle中将列varchar更改为clob
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6839545/
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 column varchar to clob in oracle
提问by Whtisop
I have a column detailsdesigned as varchar in oracle DB, this DB is being used now for customers and some rows already have data stored.
我在 oracle DB 中有一个被设计为 varchar的列详细信息,这个 DB 现在被客户使用,并且一些行已经存储了数据。
Now I want to change the column detailsto a Clob column. What is a smart way to accomplish this?
现在我想将列详细信息更改为 Clob 列。有什么聪明的方法来完成这个?
回答by Kevin Burton
(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;
回答by Sushant Butta
But this will not maintain the position of your column. It will move your column to the end of table. So if you want to maintain the position of your column as well follow these steps.
但这不会保持您的列的位置。它会将您的列移动到表格的末尾。因此,如果您想保持列的位置,也请按照以下步骤操作。
alter table atable add (tempdetails varchar2(4000));
update atable set tempdetails = details;
update atable set details = null; -- this is necessary to change data type
alter table atable modify details long; -- this is required because you can not change directly to clob.
alter table atable modify details clob;
update atable set details=tempdetails;
alter table atable drop column tempdetails;
This is the way in which you will maintain the data and position of your column intact even after changing the datatype. For detail information with example see here : http://www.oraclebin.com/2012/12/how-to-change-varchar2-to-clob-datatype.html
即使在更改数据类型后,您也可以通过这种方式保持列的数据和位置完好无损。有关示例的详细信息,请参见此处:http: //www.oraclebin.com/2012/12/how-to-change-varchar2-to-clob-datatype.html
回答by Rene
- Add a clob column to the table
- update clob column with values from varchar column
- drop varchar column
- rename clob column to varchar columns name
- 向表中添加一个clob列
- 使用 varchar 列中的值更新 clob 列
- 删除 varchar 列
- 将 clob 列重命名为 varchar 列名称
回答by ShoeLace
if you need your table data to be accessible during the process.. look at DBMS_REDEFINITION
如果您需要在此过程中访问您的表数据.. 看看 DBMS_REDEFINITION
see a similar question on asktom http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1770086700346491686
在 asktom 上看到类似的问题 http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1770086700346491686

