1
DECLARE
past_due exception;
CURSOR emp_cur IS
select distinct e.empno as enum,e.ename,e.hiredate,e.sal,e.job1,e.comm,e.deptno,e.mgr

from emp e join emp m
on m.mgr=e.empno;
c1 emp_cur%ROWTYPE;
BEGIN
OPEN emp_cur;
LOOP
    FETCH emp_cur INTO c1;
     if emp_cur%NOTFOUND then
 raise past_due;

/*  INSERT INTO newempl(emp_id,emp_nm,emp_sal)*/
     insert into newemp(dno,dname,ddate,dbasic,djob,dcomm,dept)
   values( c1.enum,c1.ename,c1.hiredate,c1.sal,c1.job1,c1.comm,c1.deptno);
   dbms_output.put_line(c1.enum||' '||c1.ename);
END LOOP;
exception
when past_due then
raise_application_error(-2100,'fetching the records is completed');

END;

我的错误是

错误报告:ORA-06550:第 20 行,PLS-00103 列:在预期以下情况之一时遇到符号“LOOP”:

如果 ORA-06550:第 25 行,第 4 列:PLS-00103:在预期以下情况之一时遇到符号“文件结尾”:

end not pragma final 可实例化顺序覆盖静态成员构造函数映射 06550。00000 -“行 %s,列 %s:\n%s” *原因:通常是 PL/SQL 编译错误。*行动:我不明白错误是什么

4

1 回答 1

2

试试这个,end if;引发异常后丢失。

DECLARE
   past_due   EXCEPTION;

   CURSOR emp_cur
   IS
      SELECT DISTINCT e.empno AS enum,
                      e.ename,
                      e.hiredate,
                      e.sal,
                      e.job1,
                      e.comm,
                      e.deptno,
                      e.mgr
        FROM emp e JOIN emp m ON m.mgr = e.empno;

   c1         emp_cur%ROWTYPE;
BEGIN
   OPEN emp_cur;

   LOOP
      FETCH emp_cur INTO c1;

      IF emp_cur%NOTFOUND
      THEN
         RAISE past_due;
      END IF;

      /*  INSERT INTO newempl(emp_id,emp_nm,emp_sal)*/
      INSERT INTO newemp (dno,
                          dname,
                          ddate,
                          dbasic,
                          djob,
                          dcomm,
                          dept)
           VALUES (c1.enum,
                   c1.ename,
                   c1.hiredate,
                   c1.sal,
                   c1.job1,
                   c1.comm,
                   c1.deptno);

      DBMS_OUTPUT.put_line (c1.enum || ' ' || c1.ename);
   END LOOP;
EXCEPTION
   WHEN past_due
   THEN
      raise_application_error (-2100, 'fetching the records is completed');
END; 
于 2012-11-15T17:42:18.303 回答