我在编译oracle中的触发器时遇到错误

时间:2015-07-18 10:23:16

标签: oracle triggers

需要有关此触发器的帮助,当用户对特定列执行更新时更新记录。 防爆。我在这里创建了一个表格订单如下。

CREATE TABLE orders
   ( order_id number(5),
     quantity number(4),
     status_c varchar2(15), 
     delete_date date,
     deleted_by_id varchar2(10));

我在其中插入了2条记录,如下所示。

insert into orders values (1,25,'FAILED',null,null);
insert into orders values (1,50,'QUEUED',null,null);

select * from orders;

ORDER_ID QUANTITY STATUS_C DELETE_DA DELETED_BY

     1         25 FAILED
     1         50 QUEUED

现在我们可以看到列STATUS_C的值为' FAILED'和' QUEUED'

所以每当新用户更新此表时 - 订单,并将状态设置为' DELETED'对于status_c,我需要捕获他的详细信息,例如person_id和sysdate,所以我在该表上写了一个下面的触发器 - Orders

CREATE OR REPLACE TRIGGER orders_before_update
  BEFORE UPDATE
     ON orders
    FOR EACH ROW

  DECLARE
     v_username varchar2(10);

  BEGIN

   If UPDATING then

        if upper(:new.status_c) = 'DELETED' then

       -- Find username of person performing UPDATE on the table
       SELECT user INTO v_username
       FROM dual;

       -- Update delete_date field to current system date
       :new.delete_date := sysdate;

       -- Update deleted_by_id field to the username of the person performing the UPDATE
       :new.deleted_by_id := v_username   

    end if;

    end if;
   END;
   /

警告:使用编译错误创建触发器。

我在编译时遇到错误。

我试图用表来看看它的影响,

    update orders set status_c = 'DELETED' where order_id = 1;
    update orders set status_c = 'DELETED' where order_id = 1
       *
ERROR at line 1:
ORA-04098: trigger 'DISDBA.ORDERS_BEFORE_UPDATE' is invalid and failed re-validation

我需要帮助触发器中的问题是什么,以及它为什么不编译。

当我使用以下查询检查错误时。它说。

 `select * from user_errors where type = 'TRIGGER' and name` ='ORDERS_BEFORE_UPDATE';

NAME                           TYPE           SEQUENCE       LINE   POSITION
------------------------------ ------------ ---------- ---------- ----------
TEXT
----------------------------------------------------------------------------------------------------
ORDERS_BEFORE_UPDATE           TRIGGER               1         20          5
PLS-00103: Encountered the symbol "END" when expecting one of the following:

   . ( * @ % & = - + ; < / > at in mod not rem
   <an exponent (**)> <> or != or ~= >= <= <> and or like
   between is null is not || is dangling
The symbol ";" was substituted for "END" to continue.

需要帮助。

1 个答案:

答案 0 :(得分:0)

在这一行上缺少分号:

       :new.deleted_by_id := v_username