Oracle Pl/SQL通过SQL*PLUS触发编译错误

Kie*_*ran 4 oracle triggers view

我在通过SQL*PLUS编译Oracle触发器时遇到问题 - 我不认为我是愚蠢的但是我看不出问题是什么.

我们有一个安装程序脚本,它本质上是一个批处理文件,它通过在多个脚本上调用SQLPLUS来创建/刷新数据库中的所有对象,每个脚本包含一个视图,触发器等.首先创建表和视图,然后触发.此时V_BS_GRIDFIELDS可能会创建或不创建下面的视图,也可能稍后由其他过程创建.视图是一个可更新的视图,因此我们在其上放置了一个触发器以将更新推送到不同的表,如下所示:

CREATE OR REPLACE FORCE TRIGGER TR_INSTUPD_BS
  INSTEAD OF INSERT OR UPDATE OR DELETE 
  ON V_BS_GRIDFIELDS
FOR EACH ROW
BEGIN

  IF INSERTING OR DELETING THEN
    NULL;
  END IF;

  IF UPDATING THEN
    -- Can only change these fields
    IF (:OLD.VISIBLE <> :NEW.VISIBLE) OR (:OLD.COMPULSORY <> :NEW.COMPULSORY) THEN 

      -- Source Table = BS_GRIDFIELDS
      IF (:OLD.SOURCE_TYPE = 0) THEN

        UPDATE BS_GRIDFIELDS BS_GF
           SET BS_GF.VISIBLE    = :NEW.VISIBLE,
               BS_GF.COMPULSORY = :NEW.COMPULSORY
         WHERE BS_GF.FIELD_NAME = :OLD.FIELD_NAME;

      END IF;
    END IF;
  END IF;
END;
Run Code Online (Sandbox Code Playgroud)

问题是oracle SQL*PLUS似乎在第6行的第一个空行后停止编译触发器:

SQL> @"TR_INSTUPD_BS.sql";
SP2-0734: unknown command beginning "IF INSERTI..." - rest of line ignored.
SP2-0042: unknown command "NULL" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0734: unknown command beginning "IF UPDATIN..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0734: unknown command beginning "IF (:OLD.V..." - rest of line ignored.
SP2-0734: unknown command beginning "IF (:OLD.S..." - rest of line ignored.
SP2-0552: Bind variable "OLD" not declared.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END" - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
Run Code Online (Sandbox Code Playgroud)

如果你删除第6行的空行,它似乎停止在第7行的第一个分号编译:

SQL> @"TR_INSTUPD_BS.sql";

Warning: Trigger created with compilation errors.

SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0734: unknown command beginning "IF UPDATIN..." - rest of line ignored.
SP2-0734: unknown command beginning "IF (:OLD.V..." - rest of line ignored.
SP2-0734: unknown command beginning "IF (:OLD.S..." - rest of line ignored.
SP2-0552: Bind variable "OLD" not declared.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END" - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SQL>
Run Code Online (Sandbox Code Playgroud)

我们有很多以这种方式创建的触发器,它们都有空格,分号等,并且创建好了.我已经在Oracle 9,10,11上测试并看到了同样的问题.任何人都可以对此有所了解吗?

谢谢.

Vin*_*rat 5

在默认设置中,SQL*Plus将无法正确处理空行,您需要发出以下命令:

SQL> SET SQLBLANKLINES on
Run Code Online (Sandbox Code Playgroud)

看到这个SO.

更新:我的回答太快,空白行似乎不是问题.我在我的数据库上尝试了你的代码,问题似乎来自FORCE关键字.在10gR2中的文件并没有提到这个关键字.删除时触发器会编译.