PLS-00103:为序列号oracle创建触发器

时间:2017-12-13 04:37:57

标签: oracle sqlplus

我有这个脚本。基本上增加表中的一个主键。

CREATE OR REPLACE FORCE TRIGGER SISD_OWNER.TRG_SN_MAP_UNIT_RELA_SEQ
BEFORE INSERT ON SISD_OWNER.ADV_SN_MAP_UNIT_RELA
FOR EACH ROW
DECLARE
  m_next_seq_num NUMBER := 0;
BEGIN
  IF :new.SEQUENCE_NUMBER is null THEN
    select
        ADV_SN_MAP_UNIT_RELA_SEQ.NextVal
    into m_next_seq_num
    from dual;
    :new.SEQUENCE_NUMBER := m_next_seq_num;
  END IF;
END;

在sqlplus(cmd)上运行时,我得到了:

LINE/COL ERROR
-------- -----------------------------------------------------------------
2/28     PLS-00103: Encountered the symbol "end-of-file" when expecting
     one of the following:
     * & = - + ; < / > at in is mod remainder not rem
     <an exponent (**)> <> or != or ~= >= <= <> and or like like2
     like4 likec between || multiset member submultiset

不确定错误究竟是什么?

2 个答案:

答案 0 :(得分:1)

如果您的数据库版本为11g或更高。 然后使用简化代码并提高工作效率的新功能。

CREATE OR REPLACE TRIGGER SISD_OWNER.TRG_SN_MAP_UNIT_RELA_SEQ
BEFORE INSERT ON SISD_OWNER.ADV_SN_MAP_UNIT_RELA
FOR EACH ROW
DECLARE

BEGIN
  IF :new.SEQUENCE_NUMBER is null THEN
    :new.SEQUENCE_NUMBER := ADV_SN_MAP_UNIT_RELA_SEQ.NextVal;
  END IF;
END;

答案 1 :(得分:0)

删除关键字API。触发器不存在该选项。 (虽然我希望它能做到 - 有时候在表或序列存在之前创建一个触发器会很好。)

enter image description here