2016-02-20 22 views
0

我正在写一个触发器,它将触发更新并插入到一个表上并插入到另一个表中。触发器看起来像这样。触发器没有触发使用引用

create or replace trigger update_test_history 
    before insert or update on demo.test_req REFERENCING NEW AS NEW OLD AS old 
    for each row 
declare 
    v_count number(1); 
begin 

    if :old.quote_request_id != null then 
     --Update History table 
     insert into demo.test_req_history 
     (history_id, 
      req_id) 
     values 
     (isisdba.req_hist_seq.nextval, 
      :old.req_id); 
     end if; 

end update_test_history; 

此触发器不适用于DML。但是,如果我删除if条件,那么它开始工作。 有人可以告诉我这是什么错误。 在此先感谢。

+0

定义“不工作”? 'null'永远不会等于任何包含'null'的值。 'null'也永远不等于另一个包括'null'的值。所以'something!= null'永远不会计算为'true'。也许你想要':old.quote_request_id不为空'。 –

+0

谢谢Jastin,它正在工作。 –

回答

1

null永远不会等于任何值,包括nullnull也永远不等于另一个值,包括null。所以声明

if(<<some expression>> != null) 
then 
    <<do something>> 
end if; 

将永远进入<<do something>>块。无论是将

if(<<some expression>> = null) 
then 
    <<do something>> 
end if; 

你必须使用三元逻辑,你正在处理null值BU说is nullis not null。看起来你可能想要

if(:old.quote_request_id is not null) 
the 
    <<do something>> 
end if;