Ris*_*hra 3 oracle plsql oracle11g database-trigger
使用以下触发器时出现错误:
create or replace trigger t1
  after insert or update  
     on student_tbl 
  declare
   pragma autonomous_transaction;
    begin
   if inserting then
 insert into stud_fees_details(stud_id,fees_balance,total_fees) 
       select stud_id,course_fees,course_fees from student_tbl s,courses_tbl c where s.stud_standard_id=c.course_id;
 elsif updating('stud_standard_id') then
insert into stud_fees_details(stud_id,fees_balance,total_fees) 
select stud_id,course_fees,course_fees from student_tbl s,courses_tbl c where s.stud_standard_id=c.course_id;
 end if;
end;
Run Code Online (Sandbox Code Playgroud)
错误是
ORA-06519: 检测到活动自治事务并回滚 ORA-06512: 在“SYSTEM.T1”,第 15 行 ORA-04088: 执行触发器“SYSTEM.T1”期间出错
ORA-06519:检测到活动的自治事务并回滚
原因:在从自治 PL/SQL 块返回之前,必须完成该块内启动的所有自治事务(提交或回滚)。如果不是,则活动的自治事务将隐式回滚并引发此错误。
操作:确保在从自治 PL/SQL 块返回之前,显式提交或回滚任何活动的自治事务。
数据库 PL/SQL 语言参考中的示例
-- Autonomous trigger on emp table:
CREATE OR REPLACE TRIGGER log_sal
  BEFORE UPDATE OF salary ON emp FOR EACH ROW
DECLARE
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  INSERT INTO log (
    log_id,
    up_date,
    new_sal,
    old_sal
  )
  VALUES (
    :old.employee_id,
    SYSDATE,
    :new.salary,
    :old.salary
  );
  COMMIT;
END;
/
Run Code Online (Sandbox Code Playgroud)
但 @a_horse_with_no_name 已经指出,自治事务在这里可能不合适。
删除自主事务编译指示后,您可能会遇到@GordonLinoff 在他的帖子中解决的问题。
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           14019 次  |  
        
|   最近记录:  |