嗨,我是一个新手,PLSQL这是我第一次使用PLSQL我如何使用PL/SQL游标for循环的触发
我用PLSQL创建触发器。这是我用来创建触发器的语法。但它给出了一个错误,因为“[Err] ORA-24344: success with compilation error
”我不知道我出错的地方。在这个触发器中,我使用了一个带有游标的for循环。 我觉得那个游标有什么问题任何人都可以帮助我弄清楚我错了什么地方。我使用Navicat来做到这一点。我这个苦苦挣扎了近5天:(在此先感谢
CREATE OR REPLACE TRIGGER "c" AFTER INSERT ON "EMP_REPORT_TO" REFERENCING OLD AS "OLD" NEW AS "NEW" FOR EACH ROW
DECLARE
miclaim_supervisor_count number;
employee_company_code number;
employee_businessunit number;
cursor projMgrsCursor is select b.BU_MEMBER_ID
from BU_MEMBER b, EMP_SUB_DIV s
where s.EMP_NO = :NEW.EMP_NO
and s.SUB_DIVISION_CODE = '02' and s.DIV_CODE = '041'
and b.BU_ID IN (select BU_ID from BU_MEMBER where BU_MEMBER_ID = :NEW.EMP_NO);
BEGIN
delete from MICL_SUPERVISORS where EMP_NO = :NEW.EMP_NO and IS_OVVERRIDDEN = 0;
select count(*) into miclaim_supervisor_count from MICL_SUPERVISORS where EMP_NO = :NEW.EMP_NO and IS_OVVERRIDDEN = 1;
select COMPANY_CODE into employee_company_code from EMPLOYEE_MASTER where EMP_NO = :NEW.EMP_NO;
if (employee_company_code = 'SOFT')then
OPEN projMgrsCursor;
FOR projMgrsCursor IN projMgrs
LOOP
insert into MICL_SUPERVISORS VALUES ((:NEW.ID), (SELECT SYSDATE FROM DUAL), :NEW.ENTRYADDEDBY_EMP_NO, 3000, 0, projMgrEmpNo, NULL,:NEW.EMP_NO);
END LOOP;
close projMgrsCursor;
else
if(miclaim_supervisor_count IS NULL or miclaim_supervisor_count<1) then
insert into MICL_SUPERVISORS VALUES ((:NEW.ID), (SELECT SYSDATE `enter code here`FROM DUAL), :NEW.ENTRYADDEDBY_EMP_NO, 3000, 0, :NEW.SUP_EMP_NO, NULL,:NEW.EMP_NO);
end if;
end if;
END;
;
变量数据类型的声明应该是基于列类型 - 例如。 “employee_company_code emplyee_master.company_code%type;”。 miclaim_supervisor_count可以是pls_integer。 – 2013-03-15 09:23:20
miclaim_supervisor_count永远不会为空,因为count(*)不会返回null。如果您只关心是否存在任何记录,请在查询中输入rownum = 1。 – 2013-03-15 09:24:33