触发器在数据库中插入

时间:2013-12-10 01:48:04

标签: sql oracle triggers insert

CREATE OR REPLACE TRIGGER no8 BEFORE INSERT ON pegawai FOR EACH ROW 
   BEGIN 
     IF :NEW."gaji" BETWEEN '1000000' AND '3000000' THEN 
         insert into pegawai
              ("no_ktp", "nama", "jenis_kel", "alamat", 
              "tgl_lahir", "gaji", "no_dep")  
         values (:new."no_ktp", :new."nama", :new."jenis_kel", :new."alamat",
                  :new."tgl_lahir", :new."gaji", :new."no_dep"); 
     END IF; 
   END;

  • 我尝试插入此查询

    插入pegawai VALUES        ('20104490002','NELA','2','SIDOARJO','14-AUG-1975','900000','5')

    但它给了我这个错误:

    ORA-04098: trigger 'SYSTEM.VALIDASI' is invalid and failed
    re-validation
    

    请帮帮我..

  • 1 个答案:

    答案 0 :(得分:1)

    对于作为触发器对象的表,您不能对触发器使用insert语句。主要不是BEFORE。它可以获得无限循环。

    如果您尝试更改要在表格中插入的值,则只需更改:new.FIELD_NAME上的字段值

    举个例子:

    IF :NEW."gaji" BETWEEN '1000000' AND '3000000' THEN
        --say that you need to change the value of :new."nama" just do:
        :new."nama":= 'new Value';
    end if;