我想更新触发触发器的同一记录。我使用“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;
/
问题是,如果有任何异常,我想更新记录以将状态设置为“失败”。任何人都可以告诉我该怎么做。
答案 0 :(得分:0)
我不确定为什么你在这里使用自治事务,为什么你必须在触发器中提交/回滚......
答案 1 :(得分:0)
这样做吗?
CREATE OR REPLACE TRIGGER GANUKA.INTF_CONTROLLER_UPLOADER
BEFORE insert ON GANUKA.INTF_CONTROLLER for each row
DECLARE
max_id INTEGER;
stat VARCHAR2(32);
begin
max_id := :new.id;
stat := :new.status;
IF STAT = 'NEW' THEN --ONLY NEW UPLOADS WILL CONTINUE FOR PROCESS
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
max_id := GANUKA.BACKOFFICE_UPDATE(max_id); --PL/SQL function
COMMIT;
:NEW.STATUS := 'COMPLETED';
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
:new.status := 'FAILED';
END;
ELSE
:NEW.STATUS := 'ABORTED';
:NEW.REMARKS :='STATUS IS NOT RECONGNIZED';
END IF;
end;
/