日期:2014-05-16  浏览次数:20687 次

请问oracle数据库有90万,用where删除最快方法
表1  user    字段  cn(char)  。。 。。 。。 后面好几个其他内容
表2  temp    字段  cn(char)    bz(int)


我现在想根据      user.cn = temp.cn  and temp.bz=0 的全部删除

有90万的数据,执行要好久,有没有一句语句能快点

------解决方案--------------------
如此多的数据不能使用delete删除,请问基表数据总共有多少,建议使用如下两条命令。
create table t_table_new as select * from t_table where user.cn = temp.cn  and temp.bz<>0;
将需要的数据通过create创建出来,然后truncate原表,然后rename将原表另命名,将新表改名为原表。
注:要注意原表的约束条件、索引之类的不会通过create...as select创建,需手动创建。(谨记),建议晚上操作。
当然,若temp.bz<>0;不多的话,也可以Insert into t_table select * from t_table_new;
------解决方案--------------------
alter table table_name nologging;
delete from table_name where ......;
alter table table_name logging;

------解决方案--------------------
1楼这样比较科学