我正在学习如何制作PL/SQL触发器。这就是我编码的,但我会遇到很多错误
这是我的教练给我的描述
为“工作”表创建一个触发器,该表将启动插入或更新或删除在“工作”表上执行的操作。该触发器将显示旧值和新值之间的薪水差异。编写一个集合PL/SQL以测试触发器的执行,以响应某些数据库操作(DML)语句(删除,插入或更新)。
这是代码:
create or replace trigger salary_diff
before delete or insert or update on Worker
for each row
when (new.Worker_id > 0 )
declare
sal_diff number;
begin
sal_diff := :new.salary - :old.salary;
dbms_output.put_line('new salary ' || :new.salar)
dbms_output.put_line('old salary ' || :old.salary)
dbms_output.put_line('difference between salary is ' || sal_diff);
end;
this is the description my instructor gave me
Create a trigger for the “Worker” table that would fire for INSERT or UPDATE or DELETE operations performed on the “Worker” table. This trigger will display the salary difference between the old values and new values. Write a bloc PL/SQL to test the execution of the trigger in response to some database manipulation (DML) statement (DELETE, INSERT, or UPDATE).
and this is the code:
create or replace trigger salary_diff
before delete or insert or update on Worker
for each row
when (new.Worker_id > 0 )
declare
sal_diff number;
begin
sal_diff := :new.salary - :old.salary;
dbms_output.put_line('new salary ' || :new.salar)
dbms_output.put_line('old salary ' || :old.salary)
dbms_output.put_line('difference between salary is ' || sal_diff);
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提到了“吨错误”,但是 - 实际上,只有两个:
dbms_output.put_line
呼叫之后丢失的semi -colon):任何列的new
值),因此 - 条款so:示例表:
触发器:testing:
testing:
(删除时,没有“差异”,因为工人不再存在。
You mentioned "tons of errors", but - really - there are only two:
DBMS_OUTPUT.PUT_LINE
calls):new
value for any column) so - remove thewhen
clauseSo: sample table:
Trigger:
Testing:
(when deleting, there's no "difference" because worker doesn't exist any more. If you'd want to see the difference anyway, use
NVL
function)