1

从猫中选择*;

尝试这个

4

2 回答 2

0

您不需要在查询中包含 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 是正确的解决方案。您肯定只想要那些申请过您即将关闭的工作的求职者吗?但是,我把它留在里面是因为我不知道你的业务规则,而且无论如何我已经改变了你的代码:)

于 2018-04-25T07:20:14.620 回答
0

你双取你的光标:

你的问题

[...]
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;
于 2018-04-25T06:31:57.020 回答