获取Oracle触发器中的当前行数据
我有一个Oracle10g触发器,它在每行之后都有一个INSERT触发事件,我希望触发器中的一些逻辑基于当前插入的行。我希望获得要插入的Users表标志列值,然后在触发器中,仅当标志为null时,才使用if-then-else进行操作。关于如何获取插入行的标志列值,有什么想法吗?我的目标是当标志列值为null时,不执行下面触发器中的任何逻辑获取Oracle触发器中的当前行数据,oracle,plsql,Oracle,Plsql,我有一个Oracle10g触发器,它在每行之后都有一个INSERT触发事件,我希望触发器中的一些逻辑基于当前插入的行。我希望获得要插入的Users表标志列值,然后在触发器中,仅当标志为null时,才使用if-then-else进行操作。关于如何获取插入行的标志列值,有什么想法吗?我的目标是当标志列值为null时,不执行下面触发器中的任何逻辑 Table: USERS Columns: id (PK generated from a DB sequence) .... (more columns
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
如果:new.flag不为null,则用
包围整个块,然后。。。如果结束
如果:new.flag不为空,则用环绕整个块。。。如果结束代码>此逻辑应该是外键的工作,而不是触发器。此逻辑应该是外键的工作,而不是触发器。
CREATE OR REPLACE TRIGGER "DBUSER"."TI_USERS"
AFTER INSERT
on Users
for each row
declare numrows INTEGER;
begin
IF ( :new.flag IS NOT NULL ) Then
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 if;
end;
ALTER TRIGGER "SIMPLEX"."TI_USERS" ENABLE