oracle创建一个触发器

时间:2013-08-19 13:01:50

标签: oracle triggers

在oracle数据库中:我尝试了以下查询:

    CREATE or REPLACE TRIGGER  myTrigger
AFTER UPDATE OR INSERT ON product
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN

    INSERT INTO h_product
    (
        H_PRODUCT_ID,
        PRODUCT_ID     
    )
    VALUES
    (
      seq_h_product.nextval,
       :new.product_id
    );

END

当我执行时,我收到此错误:

3:56:45  [UPDATE - 0 row(s), 0.000 secs]  [Error Code: 4098, SQL State: 42000]  ORA-04098: Déclencheur  'NEILA.myTrigger' non valide. Echec de la revalidation

我执行:

select object_name
from dba_objects
where object_type = 'TRIGGER'
and status = 'INVALID';

=>我在列表中得到了myTrigger! 为什么它无效?

1 个答案:

答案 0 :(得分:1)

执行以下操作,因为您错过了:new.product_id

CREATE or REPLACE TRIGGER  myTrigger
AFTER UPDATE OR INSERT ON product
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN

    INSERT INTO h_product
    (
        H_PRODUCT_ID,
        PRODUCT_ID     
    )
    VALUES
    (
      seq_h_product.nextval,
       :new.product_id
    );

END;
/