1.先增加一列 alter table tableName add temp varchar2; 2.然后使用number(t)列更新temp列 update tableName set temp=t; 3.然后删除number列 alter table tableName drop t; 4.重命名temp列为t alter table tableName rename column temp to t
update 上千万的数据会很慢很慢的。
有数据的话可以先新增一列 alter table tb add newcol varchar2(100) alter table tb nologging--不写入日志 update tb set newcol=oldcol --赋值 alter table tb drop column oldcol --删除老的 alter table tb rename column newcol to oldcol--改会老的字段名
你可以尝试做一些加快更新速度的准备,比如禁用约束和索引,禁用logging.加大日志文件大小等等
1、直接新建一张表 CREATE TABLE test (..,col varchar2(100),..) NOLOGGING --其它栏位跟你原来表一样 2、将原表数据插入新表 INSERT /*+append*/ INTO test SELECT * FROM tab 3、drop 原表 3、rename test表名为你原来的表 4、alter table tab logging
索引不能disable 可以不使用,你可以这样 alter table mytest nologging; alter index t_idx unusable; alter session set skip_unusable_indexes=true;
alter table mytest nologging; alter index t_idx unusable; alter session set skip_unusable_indexes=true;第2步和第3步的作用是啥呢,是指在这个会话周期内,索引不能使用,如果另外连接一个会话,索引一样有效,是这样么?谢谢
drop 的是原来的表,而你现在是要新的表,新表上没有你原表的index 当然要重建索引了啊
考虑了下update的redo大于insert 的最好的方法 是 重建个表 create table newtb as select * from oldtb where 1<>1 alter table newtb modify(col varchar2(100)) alter table newtb nologging --把约束都建好 把数据采用 insert /*+ append */ into newtb select * from oldtb commit 然后 truncate table oldtb drop table oldtb purge--改回原表名 rename newtb to oldtb 建索引 alter table oldtb nologging
alter table tableName add temp varchar2;
2.然后使用number(t)列更新temp列
update tableName set temp=t;
3.然后删除number列
alter table tableName drop t;
4.重命名temp列为t
alter table tableName rename column temp to t
alter table tb add newcol varchar2(100)
alter table tb nologging--不写入日志
update tb set newcol=oldcol --赋值
alter table tb drop column oldcol --删除老的
alter table tb rename column newcol to oldcol--改会老的字段名
你可以尝试做一些加快更新速度的准备,比如禁用约束和索引,禁用logging.加大日志文件大小等等
1、直接新建一张表
CREATE TABLE test (..,col varchar2(100),..) NOLOGGING --其它栏位跟你原来表一样
2、将原表数据插入新表
INSERT /*+append*/ INTO test SELECT * FROM tab
3、drop 原表
3、rename test表名为你原来的表
4、alter table tab logging
补充一点,如果你原表上有索引,那么在执行上面4个步骤完后,再rebuild INDEX
在drop原表的时候就已经把索引删掉了,还怎么rebuild呢?
有没有方法再更新表中数据的时候暂时让索引失效?
索引不能disable 可以不使用,你可以这样
alter table mytest nologging;
alter index t_idx unusable;
alter session set skip_unusable_indexes=true;
alter index t_idx unusable;
alter session set skip_unusable_indexes=true;第2步和第3步的作用是啥呢,是指在这个会话周期内,索引不能使用,如果另外连接一个会话,索引一样有效,是这样么?谢谢
考虑了下update的redo大于insert 的最好的方法 是 重建个表 create table newtb as select * from oldtb where 1<>1
alter table newtb modify(col varchar2(100))
alter table newtb nologging
--把约束都建好
把数据采用 insert /*+ append */ into newtb select * from oldtb
commit
然后
truncate table oldtb
drop table oldtb purge--改回原表名
rename newtb to oldtb
建索引
alter table oldtb nologging