日期:2014-05-16 浏览次数:21527 次
--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;
------解决方案--------------------
--要回滚的话 你在 我写的commit处 加判断 --查询要删除的这些表的表名的时候 你自己加判断
------解决方案--------------------
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;
------解决方案--------------------
truncate 是把表数据都清空了,而且回滚不便。
还是老实的用 delete 吧。
另外,删除一张表、多张表 没什么区别。 一条一条执行就是了,最多加个事务、回滚点之类的。
从业务上考虑,先标识(需要删除的数据),最后统一删除,更保险些。
------解决方案--------------------
select 'truncate table'||table_name||',' from user_tables where .......
------解决方案--------------------