尝试创建新触发器时出错 - 未正确结束

Error when trying to create a new trigger - not ended properly

我正在尝试创建一个触发器,以便每当在 table 1 中更新或删除一行时,都会在 table 2 中创建其原始副本。 sql看起来如下

create or replace trigger TRIG_table_2 BEFORE update or delete ON table_1 REFERENCING NEW AS NEW OLD AS OLD  for EACH ROW
BEGIN 
INSERT INTO table_2( 
    id
    ,value
    ,date_collected
    ,patient_id
) VALUES (
    :OLD.id
    , :OLD.value
    , :OLD.date_collected
    , :OLD.patient_id
);
END;

然而,当我 运行 这个时,我收到一条错误消息,说它 运行 成功但有错误。我检查了 user_errors table,发现了这个:

    PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   ;

我想一定是 sql 的终止方式出错了,但我不知道如何解决它。

如评论所述,我们需要触发代码。完整代码。

@astentx 说正斜杠不见了;很可能不是。我猜分号丢失了(正如 OP 的错误消息所暗示的那样)。像这样:

SQL> create or replace trigger trg_test
  2    before update on test
  3    for each row
  4  begin
  5    null                    --> semi-colon missing here
  6  end;
  7  /                         --> slash would create a trigger; without it,
                               --> cursor would just keep blinking 
Warning: Trigger created with compilation errors.

所以它有什么问题?

SQL> show err
Errors for TRIGGER TRG_TEST:

LINE/COL ERROR
-------- -----------------------------------------------------------------
3/1      PLS-00103: Encountered the symbol "END" when expecting one of the
         following:
         ;
         The symbol ";" was substituted for "END" to continue.

SQL>

对;报告了相同的错误 OP。但是,为了准确知道它,我们仍然错过了确切的触发代码。


[编辑] 一分钟前发布的代码可以:

SQL> create or replace trigger TRIG_table_2
  2  BEFORE update or delete ON table_1 REFERENCING NEW AS NEW OLD AS OLD
  3  for EACH ROW
  4  BEGIN
  5  INSERT INTO table_2(
  6      id
  7      ,value
  8      ,date_collected
  9      ,patient_id
 10  ) VALUES (
 11      :OLD.id
 12      , :OLD.value
 13      , :OLD.date_collected
 14      , :OLD.patient_id
 15  );
 16  END;
 17  /

Trigger created.

SQL>