更新触发触发器的同一记录
我想更新触发触发器的同一记录。我已经使用“BEFORE INSERT”做到了这一点 选项。但请注意,如果出现任何故障,我会使用事务来回滚操作。
CREATE OR REPLACE TRIGGER GANUKA.INTF_CONTROLLER_UPLOADER
BEFORE insert ON GANUKA.INTF_CONTROLLER for each row
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
max_id INTEGER;
stat VARCHAR2(32);
begin
select :new.id into max_id from dual;
select :new.status into stat from dual;
IF STAT = 'NEW' THEN --ONLY NEW UPLOADS WILL CONTINUE FOR PROCESS
:NEW.STATUS := 'STARTED';
max_id := GANUKA.BACKOFFICE_UPDATE(max_id); --PL/SQL function
:NEW.STATUS := 'COMPLETED';
ELSE
:NEW.STATUS := 'ABORTED';
:NEW.REMARKS :='STATUS IS NOT RECONGNIZED';
END IF;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK;
RAISE;
end;
/
问题是,如果出现任何异常,我想更新记录以将状态设置为“失败”。谁能告诉我该怎么做。
I want to update the same record which fires a trigger. I have done that using "BEFORE INSERT"
option. But note that I have use a transaction to rollback the operation if there is an any faliure.
CREATE OR REPLACE TRIGGER GANUKA.INTF_CONTROLLER_UPLOADER
BEFORE insert ON GANUKA.INTF_CONTROLLER for each row
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
max_id INTEGER;
stat VARCHAR2(32);
begin
select :new.id into max_id from dual;
select :new.status into stat from dual;
IF STAT = 'NEW' THEN --ONLY NEW UPLOADS WILL CONTINUE FOR PROCESS
:NEW.STATUS := 'STARTED';
max_id := GANUKA.BACKOFFICE_UPDATE(max_id); --PL/SQL function
:NEW.STATUS := 'COMPLETED';
ELSE
:NEW.STATUS := 'ABORTED';
:NEW.REMARKS :='STATUS IS NOT RECONGNIZED';
END IF;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK;
RAISE;
end;
/
Problem is if there is an an any exception I want to update the record to set the state as 'Failed'. Can any one tell me how to do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定为什么在这里使用自治事务以及为什么必须在触发器中提交/回滚...
I'm not sure why do you use autonomous transaction here and why do you have to commit/rollback in the trigger...
这个有作用吗?
Does this do it?