--Oracle Code --建议你把这些表明存储到一个表里面 create or replace procedure updatetable begin cursor tp_cur is select 表名 from 存储表名的表; tp_sql varchar2(400); for lp_cur in tp_cur loop dbms_output.put_line('now begin deleting table '||lp_cur.table_name); tp_sql:='delete '||lp_cur.table_name||' where col_name....'; _____此处自己更改 execute immediate tp_sql; dbms_output.put_line('finish deleting table '||lp_cur.table_name); commit; end loop; end;
create or replace procedure proc_DealTables as sSql varchar2(2000); cursor c1 is select Object_name from user_objects where Object_type='TABLE' ;--and otherswhere; 查询出你要删除的表名 begin for c2 in c1 loop sSql := ' delete from '||c2.table_name; begin execute immediate sSql; exception when others then rollback; end; end loop;
--Oracle Code
--建议你把这些表明存储到一个表里面
create or replace procedure updatetable
begin
cursor tp_cur is select 表名 from 存储表名的表;
tp_sql varchar2(400);
for lp_cur in tp_cur loop
dbms_output.put_line('now begin deleting table '||lp_cur.table_name);
tp_sql:='delete '||lp_cur.table_name||' where col_name....'; _____此处自己更改
execute immediate tp_sql;
dbms_output.put_line('finish deleting table '||lp_cur.table_name);
commit;
end loop;
end;
--查询要删除的这些表的表名的时候 你自己加判断
truncate 是不能回滚的与delete的区别 http://www.2cto.com/database/201109/105313.html
create or replace procedure proc_DealTables
as
sSql varchar2(2000);
cursor c1 is select Object_name from user_objects where Object_type='TABLE' ;--and otherswhere; 查询出你要删除的表名
begin
for c2 in c1 loop
sSql := ' delete from '||c2.table_name;
begin
execute immediate sSql;
exception
when others then
rollback;
end;
end loop;
end;
从业务上考虑,先标识(需要删除的数据),最后统一删除,更保险些。
我向请问下:如何使用cursor进行循环取值-表的名称,然后用truncate来删除每个表的数据。谢谢!
把你所要删除的表放到一个配置表中,写个存储过程,开游标将表名一个一个的带出来,动态语句删除
select 'truncate table'||table_name||','
from user_tables
where .......导出到csv
用txt打开复制到commande窗口执行
8楼正是你想要的东西!!仔细看看吧,楼主,只不过里面没有commit