日期:2014-05-17  浏览次数:20813 次

存储过程执行无效

需求很简单,我想把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;

------解决方案--------------------
引用:
-- 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;

上面理解可能有误,下面的是只删除system用户下的重复表
-- system用户登录
create or replace procedure dr_table is 
cursor c1 is 
select table_name from all_tables a where owner='SYSTEM' and