代码:
1、
create or replace package types as
       type cur_emp is ref cursor;
       procedure pr_getMaxAge(ce out cur_emp);
end ;2、
create package body types is
procedure pr_getMaxAge(ce out cur_emp) asbegin
  open ce for select * from empl e;
end pr_getMaxAge;
end;3、
declare emp types.cur_emp;
begin
   types.pr_getMaxAge(emp);
   for myem in emp loop
       dbms_output.put_line(myem.id);
   end loop;
end;这是在pl/sql上写的代码,上面的几段代码分别写在不同的sql窗口中,第1、2执行都没有问题,但第三个执行就报错了
ORA-06550:第4行,第16列:
PLS-00221:'EMP'不是过程或没未定义
ORA-06550:第4行,第4列:
PL/SQL:Statemant ignored请问,这是什么问题?怎么解决呢?

解决方案 »

  1.   

    要不你把types换个名字试试看呗?
      

  2.   

    declare
       emp types.cur_emp;
       row empl%rowtype;
    begin
       types.pr_getMaxAge(emp);
       loop
          fetch emp into row;
          exit when emp%notfound;
          dbms_output.put_line(row.id);
       end loop;
       close emp;
    end;
      

  3.   

    --此处不能使用for游标循环,因为emp游标已打开,不能再打开,可以使用普通游标循环
    DECLARE
      emp types.cur_emp;
      e1  emp1%ROWTYPE;
    BEGIN
      types.pr_getMaxAge(emp);
      /*for myem in emp loop
      dbms_output.put_line(myem.id);
      end loop;*/
      LOOP
        FETCH emp
          INTO e1;
        EXIT WHEN emp%NOTFOUND;
        dbms_output.put_line(e1.id);
      END LOOP;
    END;