插入条件后创建触发器

Create a trigger after insert with a condition

我想创建一个触发器,以便在验证特定条件时插入另一个 table ID 行。

SWAB_TEST

id_swab
id_user 
result

NO_INFECTED

id_user

例如我想插入 NO_INFECTED table 拭子测试为阴性的用户 ID

SWAB_TEST

id_swab : Test1
id_user : 1
result  : negative

NO_INFECTED

id_user: 1

我创建了这个触发器,但我不知道如何插入条件

CREATE OR REPLACE TRIGGER test_trigg 
AFTER INSERT ON swab_test
FOR EACH ROW
BEGIN
 INSERT INTO no_infected (id_user)
 VALUES(:new.id_user);
END;

只需添加一个IF条件和:new.result = 'negative'控制即可:

CREATE OR REPLACE TRIGGER test_trigg 
AFTER INSERT ON swab_test
FOR EACH ROW
BEGIN
IF :new.result = 'negative' THEN
 INSERT INTO no_infected (id_user)
 VALUES (:new.id_user);
END IF;
END;
/