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

游标里面可以使用drop吗?
写了下面的语句 
  1 declare
  2 new_name user_source.name%type;
  3 cursor cursor_1
  4 is
  5 select name from user_source;
  6 begin
  7 for myrecord in cursor_1 loop
  8 dbms_output.put_line(myrecord.name);
  9 drop procedure myrecord.name;
 10 end loop;
 11* end;
 12 /

运行出错,错误如下
drop procedure myrecord.name;
*
第 9 行出现错误:
ORA-06550: 第 9 行, 第 2 列:
PLS-00103: 出现符号 "DROP"在需要下列之一时:
begin case declare end
exit for goto if loop mod null pragma raise return select
update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe

求高手解答

------解决方案--------------------
请参考:
SQL code

DECLARE
    new_name user_source.name%type;
    CURSOR cursor_1 IS SELECT name FROM user_source;
BEGIN
    FOR myrecord IN cursor_1 LOOP
        dbms_output.put_line(myrecord.name);
        -- 本地动态执行DDL
        EXECUTE IMMEDIATE 'drop procedure '|| myrecord.name;
    END LOOP;
END;