您已经以块显示代码。但似乎你正在运行什么你一起显示为脚本,最初不知道更新:
drop table SalUpdates cascade constraints;
create table SalUpdates(
SalSSN char(9),
newSalary decimal(10,2),
oldSalary decimal(10,2)
);
create or replace trigger t1
after update of salary on employee
for each row
begin
insert into SalUpdates values (:old.Ssn, :new.salary, :old.salary);
end;
当作为一个脚本在SQL Developer中运行该脚本输出窗口显示:
drop table SalUpdates cascade constraints
Error report -
ORA-00942: table or view does not exist
00942. 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 t1
after update of salary on employee
for each row
begin
insert into SalUpdates values (:old.Ssn, :new.salary, :old.salary);
end;
update employee
set salary=4000
where ssn='123456789';
你:
Table SALUPDATES dropped.
Table SALUPDATES created.
Trigger T1 compiled
Errors: check compiler log
如果您然后尝试运行它自己的更新(作为语句而不是脚本;或者通过选择测试并运行一个脚本),你确实得到:
SQL Error: ORA-04098: trigger 'MYSCHEMA.T1' is invalid and failed re-validation
04098. 00000 - "trigger '%s.%s' is invalid and failed re-validation"
*Cause: A trigger was attempted to be retrieved for execution and was
found to be invalid. This also means that compilation/authorization
failed 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块必须用斜杠来终止它,as it explains in the SQL*Plus documentation(这主要是适用于SQL开发人员太):
的SQL * Plus把PL/SQL子程序以同样的方式作为SQL命令,除了分号(;)或空行不会终止并执行块。通过在新行上输入句点(。)自行终止PL/SQL子程序。您也可以通过在新行上自行输入斜线(/)来终止和执行PL/SQL子程序。
如果添加斜线到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 t1
after update of salary on employee
for each row
begin
insert into SalUpdates values (:old.Ssn, :new.salary, :old.salary);
end;
/
update employee
set salary=4000
where ssn='123456789';
,你现在看到的:
Table SALUPDATES dropped.
Table SALUPDATES created.
Trigger T1 compiled
1 row updated.
似乎罚款。你确定错误信息指的是'T1' - 你还没有尝试用不同的名字创建触发器吗?你可以查询'user_errors'视图来查看哪些是错误的。如果这不能让你清楚,请将相关错误添加到您的问题中。 –
创建触发器后,是否有机会丢弃'SalUpdates'? – Plirkee
当我运行我的整个脚本时,触发器没有问题,但现在我收到错误“遇到符号更新”为什么? – Gary