我有一个列细节设计为varchar在oracle数据库中,这个数据库现在正在为客户使用,一些行已经存储了数据。
现在,我想将列详细信息更改为Clob列。实现这一目标的聪明方法是什么?
发布于 2011-07-27 15:30:34
(和前面的答案一样)下面是代码:
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;
发布于 2013-01-25 12:41:25
但这将不会保持您的专栏的位置。它会将您的列移动到表的末尾。因此,如果您还想保持列的位置,请遵循以下步骤。
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;
这是即使在更改数据类型之后也能保持列的数据和位置不变的方式。有关示例的详细信息,请参阅此处:http://www.oraclebin.com/2012/12/how-to-change-varchar2-to-clob-datatype.html
发布于 2012-03-21 13:43:49
如果您需要在此过程中访问表数据..看看DBMS_REDEFINITION
在asktom http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1770086700346491686上查看类似的问题。
https://stackoverflow.com/questions/6839545
复制相似问题