【发布时间】:2010-12-12 23:58:19
【问题描述】:
我在通过 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;
问题是 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.
如果删除第 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>
我们有很多以这种方式创建的触发器,它们都有空格、分号等,并且可以正常创建。我在 Oracle 9、10、11 上测试并看到了同样的问题。有人能解释一下吗?
谢谢。
【问题讨论】: