我想触发表格上的每个插页。有时,name_event是可用目标表的存储库,可以插入它。有时它不可用,而且我需要检查文件夹表中的代码:
create or replace TRIGGER scheme2.Logger
BEFORE INSERT OR UPDATE ON scheme2.payments
FOR EACH ROW
BEGIN
INSERT INTO scheme1.db(ID, NAME_EVENT, TIME_EVENT)
VALUES( :NEW.id
, IF (select repo.code
from scheme2.repository repo
where repo.id = :NEW.repository_id) IS NOT NULL
THEN
(select repo.code
from scheme2.pay_repository repo
where repo.id = :NEW.repository_id)
ELSE
(select env.repository_code
from scheme2.folder env
where env.id = :NEW.folder_id)
, SYSDATE);
END;
我试过这段代码,但是我遇到了编译错误:
Error(2,1): PL/SQL: SQL Statement ignored
第2行是每行的行
Error(4,5): PL/SQL: ORA-00936: Unknown expression.
第4行是插入行
如何解决错误?
答案 0 :(得分:3)
create or replace TRIGGER scheme2.Logger BEFORE INSERT OR UPDATE ON scheme2.payments
FOR EACH ROW
declare
VAR_NEVENT number(3);
BEGIN
select repo.code into VAR_NEVENT from scheme2.repository repo
where repo.id = :NEW.repository_id)
IF VAR_NEVENT IS NOT NULL THEN
select repo.code INTO VAR_NEVENT from scheme2.pay_repository repo where repo.id = :NEW.repository_id
ELSE (select env.repository_code into VAR_NEVENT from scheme2.folder env where env.id = :NEW.folder_id)
END IF;
INSERT INTO scheme1.db(ID, NAME_EVENT, TIME_EVENT)
VALUES(:NEW.id, VAR_NEVENT , SYSDATE);
END;
类似于上面的内容..首先在变量中选择结果,然后将其插入表中。