how to insert nextval to trigger inside for loop

℡╲_俬逩灬. 提交于 2019-12-08 23:29:27

Why not including calculation of micl_sup_id_seq.nextval into your cursor?

cursor  projMgrsCursor is 
  select b.BU_MEMBER_ID, micl_sup_id_seq.nextval SUPID
  from ...

Try rewriting your code as:

DECLARE
  nSupid   NUMBER;
  projMgr  VARCHAR2(32767);
BEGIN
  OPEN  projMgrsCursor;

  LOOP
    FETCH projMgrsCursor INTO projMgr;
    EXIT WHEN projMgrsCursor%NOTFOUND;

    select micl_sup_id_seq.nextval into nSUPID from dual;

    insert into MICL_SUP 
      (SUPID, ASSIGNED_DATE, ASSIGNED_BY_EMP_NO,   AMOUNT_LIMIT,
       IS_OVERRIDDEN, SUP_EMP_NO, RTD_EMP, EMP_NO)
    VALUES
      (nSupid, SYSDATE,  :NEW.ENTRYADDEDBY_EMP_NO, 3000,
       0,              projMgr,   NULL,    :NEW.EMP_NO);
   END LOOP;    

  CLOSE projMgrsCursor;

  DBMS_OUTPUT.PUT_LINE('Successful completion');
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Exception: ' || SQLCODE || '  ' || SQLERRM);
    RAISE;
END;

Share and enjoy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!