2

テーブル内のいくつかのフィールド用のトリガーがあります。しかし、何らかの理由で、別のフィールドが変更された場合(トリガーで定義されていない場合)、それでも起動します。

CREATE OR REPLACE TRIGGER INTEGRATION_EMPLOYMENT
    AFTER UPDATE OF start_day_of_employment, end_of_employment ON hr_employment_data
    FOR EACH ROW
    DECLARE
    BEGIN
         IF UPDATING THEN
            MERGE INTO ad_integration intg USING dual ON (intg.user_id = :NEW.user_id AND intg.integrated = 'NO')
            WHEN MATCHED THEN
                UPDATE SET
                         intg.start_day_of_employment = decode(:NEW.start_day_of_employment, NULL, ' ', :NEW.start_day_of_employment),
                         intg.end_of_employment = decode(:NEW.end_of_employment, NULL, ' ', :NEW.end_of_employment),
                         intg.manager_status = :NEW.manager_status,
                         intg.pid = (SELECT pid FROM arc.user_info WHERE user_id = :NEW.user_id),
                         intg.network_access_start_date = (SELECT network_access_start_date FROM hr_extension_data WHERE user_id = :NEW.user_id)
             WHEN NOT MATCHED THEN
                INSERT (intg.user_id, intg.start_day_of_employment, intg.end_of_employment, intg.manager_status, intg.pid, intg.network_access_start_date
                VALUES (:NEW.user_id, :NEW.start_day_of_employment, :NEW.end_of_employment, :NEW.manager_status, (SELECT pid FROM arc.user_info WHERE user_id = :NEW.user_id), (SELECT network_access_start_date FROM hr_extension_data WHERE user_id = :NEW.user_id));
END IF;

END HR_ADINTEGRATION_EMPLOYMENT;

DUALを使用しているためか、何か足りないものがありますか?

乾杯!:-)

4

1 に答える 1

2

構造をそのままにして、特定のフィールドが変更されたときにのみトリガーを処理する場合は、簡単な比較を行います (新しいコード行 7 と 8):

CREATE OR REPLACE TRIGGER INTEGRATION_EMPLOYMENT
AFTER UPDATE OF start_day_of_employment, end_of_employment ON hr_employment_data
FOR EACH ROW
DECLARE
BEGIN
     IF UPDATING 
        AND (:NEW.start_day_of_employment <> :OLD.start_day_of_employment
        OR   :NEW.end_of_employment <> :OLD.end_of_employment)  THEN
        MERGE INTO ad_integration intg USING dual ON (intg.user_id = :NEW.user_id AND intg.integrated = 'NO')
        WHEN MATCHED THEN
            UPDATE SET
                     intg.start_day_of_employment = decode(:NEW.start_day_of_employment, NULL, ' ', :NEW.start_day_of_employment),
                     intg.end_of_employment = decode(:NEW.end_of_employment, NULL, ' ', :NEW.end_of_employment),
                     intg.manager_status = :NEW.manager_status,
                     intg.pid = (SELECT pid FROM arc.user_info WHERE user_id = :NEW.user_id),
                     intg.network_access_start_date = (SELECT network_access_start_date FROM hr_extension_data WHERE user_id = :NEW.user_id)
         WHEN NOT MATCHED THEN
            INSERT (intg.user_id, intg.start_day_of_employment, intg.end_of_employment, intg.manager_status, intg.pid, intg.network_access_start_date
            VALUES (:NEW.user_id, :NEW.start_day_of_employment, :NEW.end_of_employment, :NEW.manager_status, (SELECT pid FROM arc.user_info WHERE user_id = :NEW.user_id), (SELECT network_access_start_date FROM hr_extension_data WHERE user_id = :NEW.user_id));
END IF;

END HR_ADINTEGRATION_EMPLOYMENT;
于 2012-10-18T10:10:50.343 に答える