CREATE OR REPLACE TRIGGER On_WORK_Insert AFTER INSERT ON WORK FOR EACH

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
CREATE OR REPLACE TRIGGER On_WORK_Insert
AFTER INSERT ON WORK
FOR EACH ROW
DECLARE
rowcount integer(2);
BEGIN
/* Считаем доступные строки */
SELECT Count (*) INTO rowcount
FROM TRANSACTION
WHERE CustomerID IS NULL AND WorkID=:new.WorkID;
IF rowcount> 0 Then /* Строка существует, ничего не предпринимаем */
DBMS_OUTPUT.PUT_LINE ('Matching rows in the table TRANSACTION there - no action taken');
RETURN;
ELSE /* Нужно добавить новую строку */
INSERT INTO TRANSACTION (TransactionID, DATEACQUIRED, WorkID)
VALUES (TransID.NextVal, SysDate, :new.WorkID);
END IF;
END;
/