从猫中选择*;
尝试这个
您不需要在查询中包含 JOB 表。您在 :NEW 命名空间中拥有所需的信息。在查询中不包括 JOB 表将停止ORA-04091
错误。
您还有两组游标控制语句。选一个。我更喜欢隐式游标语法,因为它打字更少(并且效率略高)。
CREATE OR REPLACE TRIGGER Display_Update_Message
BEFORE UPDATE ON JOBS
FOR EACH ROW WHEN ((old.IsFilled != new.IsFilled) AND (new.isFilled = 'yes'))
BEGIN
DBMS_OUTPUT.PUT_LINE('Seekers affected by closing job '
|| :new.JobID || ': ' || :new.JobName);
FOR UT IN (SELECT JS.LastName
, JS.FirstName
, JS.Email Email
FROM JOBAPPLICATIONS JA
FULL OUTER JOIN JOBSEEKERS JS ON JA.JSID = JS.JSID
WHERE JA.JobID = :new.JobID )
LOOP
DBMS_OUTPUT.PUT_LINE('--' || UT.LastName || ', ' || UT.FirstName || ' ' || UT.Email);
END LOOP;
:new.StopDate := sysdate;
END;
/
顺便说一句,我不确定为什么您的光标中有 FULL OUTER JOIN。我会认为 INNER JOIN 是正确的解决方案。您肯定只想要那些申请过您即将关闭的工作的求职者吗?但是,我把它留在里面是因为我不知道你的业务规则,而且无论如何我已经改变了你的代码:)
你双取你的光标:
[...]
OPEN UPDATETRIGGER;
FOR UT IN UPDATETRIGGER -- This performs fetching into UT
LOOP
FETCH UPDATETRIGGER -- Here You Fetch again..
[...]
CREATE OR REPLACE TRIGGER Display_Update_Message
BEFORE UPDATE
ON JOBS
FOR EACH ROW
WHEN ( (old.IsFilled != new.IsFilled) AND (new.isFilled = 'yes'))
DECLARE
CURSOR UPDATETRIGGER
IS
SELECT J.JobID JobID,
J.JobName JobName,
J.StopDate StopDate,
JS.LastName LastName,
JS.FirstName FirstName,
JS.Email Email
FROM JOBS J
FULL OUTER JOIN JOBAPPLICATIONS JA ON J.JobID = JA.JobID
FULL OUTER JOIN JOBSEEKERS JS ON JA.JSID = JS.JSID
WHERE J.JobID = :new.JobID;
JobID NUMBER (3);
JobName CHAR (30);
LastName CHAR (15);
FirstName CHAR (15);
Email CHAR (30);
StopDate DATE;
BEGIN
DBMS_OUTPUT.PUT_LINE (
'Seekers affected by closing job ' || JobID || ': ' || :new.JobName);
OPEN UPDATETRIGGER;
LOOP -- infinite loop
FETCH UPDATETRIGGER
INTO JobID,
JobName,
LastName,
FirstName,
Email,
StopDate;
EXIT WHEN UPDATETRIGGER%NOTFOUND; -- loop-breaker
:new.StopDate := SYSDATE;
DBMS_OUTPUT.PUT_LINE (
'--' || UT.LastName || ', ' || UT.FirstName || ' ' || UT.Email);
END LOOP;
CLOSE UPDATETRIGGER;
END;