我写了以下一个存储过程:
create or replace procedure droptablebak
is
sqlt varchar2(200);
zd varchar2 (100);
CURSOR tb is (select * from user_tables where table_name like 'TEST%');
R_emp tb%ROWTYPE;
begin
open tb;
loop
fetch tb into R_emp;
exit when tb% notfound;
zd:= R_emp.table_name;
sqlt := 'drop table ' || zd || ' ; ';
dbms_output.put_line(sqlt);
execute immediate sqlt;
end loop;
close tb;
end;
编译通过,但在执行exec droptablebak的时候,报错,提示ORA-06512的错误。
请问这个存储过程exec droptablebak怎么样才执行成功?
create or replace procedure droptablebak
is
sqlt varchar2(200);
zd varchar2 (100);
CURSOR tb is (select * from user_tables where table_name like 'TEST%');
R_emp tb%ROWTYPE;
begin
open tb;
loop
fetch tb into R_emp;
exit when tb% notfound;
zd:= R_emp.table_name;
sqlt := 'drop table ' || zd || ' ; ';
dbms_output.put_line(sqlt);
execute immediate sqlt;
end loop;
close tb;
end;
编译通过,但在执行exec droptablebak的时候,报错,提示ORA-06512的错误。
请问这个存储过程exec droptablebak怎么样才执行成功?
sqlt := 'drop table ' || zd || ' ; ';
改成
sqlt := 'drop table ' || zd;
看看,动态sql语句里面是不带;的。