我有一个 Oracle 10g 触发器,它在每一行之后都有一个 INSERT 触发事件,我想在触发器中基于当前插入的行的一些逻辑。我想获取插入的用户表标志列值,然后在触发器中,仅当标志为空时才使用 if-then-else 执行某些操作。关于如何获取被插入行的标志列值的任何想法?我的目标是在标志列值为空时不执行以下触发器中的任何逻辑。
Table: USERS
Columns:
id (PK generated from a DB sequence)
.... (more columns)
flag VARCHAR2(1 BYTE) and is nullable
扳机:
//goal is to not do any of the logic in the trigger below when flag is null
CREATE OR REPLACE TRIGGER "DBUSER"."TI_USERS"
AFTER INSERT
on Users
for each row
declare numrows INTEGER;
begin
select count(*) into numrows
from Customer
where
/* %JoinFKPK(:%New,Customer," = "," and") */
:new.Customer_Key = Customer.Customer_Key;
if (
/* %NotnullFK(:%New," is not null and") */
numrows = 0
)
then
raise_application_error(
-20002,
'Cannot INSERT Users because Customer does not exist.'
);
end if;
end;
ALTER TRIGGER "SIMPLEX"."TI_USERS" ENABLE