需求很简单,我想把system用户下与test用户共有的表删除,但是存储过程执行后并没有删除,也没报错,不知道是什么问题,请大神看看
create or replace procedure dr_table is 
cursor c1 is 
select 'drop table '||table_name||' cascade constraints' v_name from all_tables a where owner='SYSTEM' and 
exists(select table_name from all_tables b where owner='TEST' and a.TABLE_NAME=b.TABLE_NAME);
sqlstr varchar2(1000);
begin
  for i in c1 loop
    sqlstr:=i.v_name;
    --dbms_output.put_line(sqlstr);
    execute immediate sqlstr;
  end loop;
end;

解决方案 »

  1.   

    -- dba用户执行
    create or replace procedure dr_table is 
    cursor c1 is 
    select table_name from all_tables a where owner='SYSTEM' and 
    exists(select table_name from all_tables b where owner='TEST' and a.TABLE_NAME=b.TABLE_NAME);
    sqlstr varchar2(1000);
    begin
      for i in c1 loop
        sqlstr:='drop table SYSTEM.'||i.table_name||' cascade constraints';
        execute immediate sqlstr;
        sqlstr:='drop table TEST.'||i.table_name||' cascade constraints';
        execute immediate sqlstr;
      end loop;
    end;
      

  2.   

    上面理解可能有误,下面的是只删除system用户下的重复表
    -- system用户登录
    create or replace procedure dr_table is 
    cursor c1 is 
    select table_name from all_tables a where owner='SYSTEM' and 
    exists(select table_name from all_tables b where owner='TEST' and a.TABLE_NAME=b.TABLE_NAME);
    sqlstr varchar2(1000);
    begin
      for i in c1 loop
        sqlstr:='drop table '||i.table_name||' cascade constraints';
        execute immediate sqlstr;
      end loop;
    end;
      

  3.   

    sqlstr:='drop table SYSTEM.'||i.table_name||' cascade constraints';
      

  4.   

    一般加个exception捕获异常。先看看select from all_tables where exists有没有找到数据。
      

  5.   

    已经解决了,过程没有问题,问题是赋予了select any table权限