PLS-00103:在预期以下情况之一时遇到符号“”:

时间:2021-07-08 18:37:03

标签: sql oracle plsql oracle10g datagrip

我有以下 PL/SQL 触发器,我想在我的 Oracle XE 服务器上执行。对于学校项目,我们需要使用触发器进行自动增量。

CREATE OR REPLACE TRIGGER tr_br_i_firma_id_autoinc
    BEFORE INSERT ON FIRMA
    FOR EACH ROW
WHEN(new.FIRMA_ID IS NULL)
BEGIN
    SELECT seq_firma.NEXTVAL into :new.FIRMA_ID
    FROM DUAL;
END;
/

它似乎有效,因为它完成时只发出警告,但是当我现在运行插入时,它说触发器不起作用。 但是当我通过 SQLWorkbench 运行触发器时,它可以正常工作而没有任何警告,然后我可以再次通过 DataGrip 运行插入命令。

DataGrip 控制台在执行后给我这个:

AUTOMATENMANAGER> CREATE OR REPLACE TRIGGER tr_br_i_firma_id_autoinc
                    BEFORE INSERT ON FIRMA
                    FOR EACH ROW
                  WHEN(new.FIRMA_ID IS NULL)
                  BEGIN
                    SELECT seq_firma.NEXTVAL into :new.FIRMA_ID
                    FROM DUAL;
                  END;
[2021-07-08 20:18:04] [99999][17110] Warning: execution completed with warning
[2021-07-08 20:18:04] completed in 20 ms
[2021-07-08 20:18:04] 1:6:PLS-00103: Encountered the symbol "" when expecting one of the following:
[2021-07-08 20:18:04] begin case declare exit for goto if loop mod null pragma
[2021-07-08 20:18:04] raise return select update while with <an identifier>
[2021-07-08 20:18:04] <a double-quoted delimited-identifier> <a bind variable> <<
[2021-07-08 20:18:04] close current delete fetch lock insert open rollback
[2021-07-08 20:18:04] savepoint set sql execute commit forall merge pipe
[2021-07-08 20:18:04] The symbol "" was ignored.
[2021-07-08 20:18:04] 2:45:PLS-00103: Encountered the symbol "" when expecting one of the following:
[2021-07-08 20:18:04] .
[2021-07-08 20:18:04] ( , % from indicator

我搜索了有关此错误消息的所有问题,但似乎找不到适合的问题... 我有语法错误还是遗漏了什么?

1 个答案:

答案 0 :(得分:0)

您发布的代码在 Oracle 11g 上运行良好。我不再有 10g,但是 - 我会说它也应该适用于该版本。这是一个演示:

SQL> create table firma (firma_id number, name varchar2(10));

Table created.

SQL> create sequence seq_firma;

Sequence created.

SQL> CREATE OR REPLACE TRIGGER tr_br_i_firma_id_autoinc
  2      BEFORE INSERT ON FIRMA
  3      FOR EACH ROW
  4  WHEN(new.FIRMA_ID IS NULL)
  5  BEGIN
  6      SELECT seq_firma.NEXTVAL into :new.FIRMA_ID
  7      FROM DUAL;
  8  END;
  9  /

Trigger created.

SQL> insert into firma (name) values ('Audi');

1 row created.

SQL> select * from firma;

  FIRMA_ID NAME
---------- ----------
         1 Audi

SQL>

这看起来很可疑:

[2021-07-08 20:18:04] 1:6:PLS-00103: Encountered the symbol "" when expecting
                      ---
                      I read this as "line 1, column 6"

如果是这样,第 1 行/第 6 列的位置是这样的:

CREATE OR REPLACE TRIGGER tr
------
123456

也许“DataGrip 控制台”(我不知道它是什么)不支持 or replace 子句,所以 - 也许您应该尝试组合 DROP + CREATE,即

drop trigger tr_br_i_firma_id_autoinc;
create trigger tr_br_i_firma_id_autoinc
  before insert on firma
  ...
end;
/
相关问题