I had a problem compiling an Oracle trigger via SQL * PLUS. I don’t think I'm stupid, but I don’t understand what the problem is.
We have a script installer, which is a batch file that creates / updates all objects in the database, calling SQLPLUS on several scripts, each of which contains one view, trigger, etc. Tables and views are created first, then triggers. The V_BS_GRIDFIELDS below may or may not be created at this point, or may be created later by another process. A view is an updatable view, so we have a trigger that fits on it to push updates for different tables, as shown below:
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
The problem is that ORACLE SQL * PLUS seems to stop compiling the trigger after the first empty line, on line 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.
If you delete an empty line in line 6, it will stop compiling at the first semicolon, in line 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>
We have many triggers created this way, and they all have spaces, semicolons, etc. and are created OK. I tested and saw the same problem on Oracle 9, 10, 11. Can anyone shed some light on this?
Thanks.