1
votes
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;

my error is

Error report: ORA-06550: line 20, column PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:

if ORA-06550: line 25, column 4: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

end not pragma final instantiable order overriding static member constructor map 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action: i am not understaning what the error is

1

1 Answers

1
votes

Try with this, end if; was missing after raising exception.

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;