您已按块显示了代码。但似乎您正在运行一起显示为脚本的内容,最初没有进行更新:
drop table SalUpdates cascade constraints;create table SalUpdates(SalSSN char(9), newSalary decimal(10,2), oldSalary decimal(10,2));create or replace trigger t1after update of salary on employeefor each rowbegininsert into SalUpdates values (:old.Ssn, :new.salary, :old.salary); end;
在SQL Developer中作为脚本运行时,脚本输出窗口显示:
drop table SalUpdates cascade constraintsError report -ORA-00942: table or view does not exist00942. 00000 - "table or view does not exist"*Cause: *Action:Table SALUPDATES created.Trigger T1 compiled
如果然后将update语句添加到脚本中:
drop table SalUpdates cascade constraints;create table SalUpdates(SalSSN char(9), newSalary decimal(10,2), oldSalary decimal(10,2));create or replace trigger t1after update of salary on employeefor each rowbegininsert into SalUpdates values (:old.Ssn, :new.salary, :old.salary); end;update employeeset salary=4000where ssn='123456789';
你得到:
Table SALUPDATES dropped.Table SALUPDATES created.Trigger T1 compiledErrors: check compiler log
如果然后尝试独自运行更新(作为语句而不是脚本;或者通过选择该测试并作为脚本运行),则确实可以得到:
SQL Error: ORA-04098: trigger 'MYSCHEMA.T1' is invalid and failed re-validation04098. 00000 - "trigger '%s.%s' is invalid and failed re-validation"*Cause: A trigger was attempted to be retrieved for execution and wasfound to be invalid. This also means that compilation/authorizationfailed for the trigger.*Action: Options are to resolve the compilation/authorization errors,disable the trigger, or drop the trigger.
如果查询
user_errors视图或运行
show errors,则会看到:
PLS-00103: Encountered the symbol "UPDATE"
问题是您没有
create trigger正确完成该语句。该
update被视为相同的PL / SQL块的一部分; 无效的部分,但仍包含在内。
当您拥有PL /
SQL块时,必须使用斜杠将其终止,如在SQL*Plus文档(大多数情况下也适用于SQLDeveloper)中所解释的那样:
SQL * Plus以与SQL命令相同的方式对待PL /
SQL子程序,除了分号(;)或空白行不会终止并执行块之外。通过在新行上单独输入一个句点(。)来终止PL /
SQL子程序。您还可以通过在新行上单独输入一个斜杠(/)来终止并执行PL / SQL子程序。
但是,SQL Developer不会抱怨脚本中的最后一个块是否没有终止斜杠,因此您的原始脚本(不进行更新)可以工作;在SQL *Plus中,它将位于提示符处。从某种意义上讲,它应该在那里-
试图有所帮助。当您添加
update语句时,它不再是脚本的结尾,因此不再适用。
如果在PL / SQL代码和以下SQL语句之间在脚本中添加斜杠,则所有斜杠都有效:
drop table SalUpdates cascade constraints;create table SalUpdates(SalSSN char(9), newSalary decimal(10,2), oldSalary decimal(10,2));create or replace trigger t1after update of salary on employeefor each rowbegininsert into SalUpdates values (:old.Ssn, :new.salary, :old.salary); end;/update employeeset salary=4000where ssn='123456789';
您现在看到:
Table SALUPDATES dropped.Table SALUPDATES created.Trigger T1 compiled1 row updated.



