存储过程执行无效

JS 2013-07-10 02:45:51

需求很简单,我想把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;
...全文
295 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
JS 2013-07-12
  • 打赏
  • 举报
回复
已经解决了,过程没有问题,问题是赋予了select any table权限
shy315 2013-07-11
  • 打赏
  • 举报
回复
一般加个exception捕获异常。先看看select from all_tables where exists有没有找到数据。
JS 2013-07-11
  • 打赏
  • 举报
回复
不行,还是不能删除,但是存储过程没有错误啊,不知道是什么问题。
jascjasc 2013-07-10
  • 打赏
  • 举报
回复
sqlstr:='drop table SYSTEM.'||i.table_name||' cascade constraints';
jascjasc 2013-07-10
  • 打赏
  • 举报
回复
引用 1 楼 jascjasc 的回复:
-- 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 
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;
jascjasc 2013-07-10
  • 打赏
  • 举报
回复
-- 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;

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧