在Oracle 12c(12.2.0.1.0)中如何处理ORA-00028“您的会话已被杀死?”

问题描述 投票:2回答:1

问题是,处理错误ORA-00028有点棘手。请查看下面的代码。

如果您在会话1中运行proc1,而它仍在运行,则使用ALTER SYSTEM KILL SESSION杀死会话1,那么您会收到ORA-00028错误消息,并且llog表中没有行。如果运行proc1并使其完成(1分钟),则错误处理将按预期进行,并且在llog表中将不会显示任何错误消息和1行。但是有趣的是,如果之后您再次运行proc1并终止该会话,则不会收到任何错误消息(已处理ORA-00028),并且在llog表中又没有一行。

因此,要在异常子句中处理ORA-00028,您需要首先捕获一些其他错误。这似乎是一个错误。有人遇到过这个问题吗?

/* creating simple table with logs */

create table llog(time timestamp, error varchar2(4000));
/

/* creating package */

create or replace package my_pack
is
       procedure proc1;
end;
/
/* creating package body*/

create or replace package body my_pack
is

e_session_killed EXCEPTION;
PRAGMA EXCEPTION_INIT(e_session_killed, -00028);


procedure error_log (time llog.time%type, error llog.error%type) is
  pragma autonomous_transaction;
begin
  insert into llog values (time, error); 
  commit;
end;


procedure proc1 is
begin

  dbms_lock.sleep(60);

  raise too_many_rows;

  exception
    when e_session_killed then
      error_log(systimestamp, sqlerrm);

    when others then
      error_log(systimestamp, sqlerrm);

end;

end;
oracle error-handling oracle12c kill-process
1个回答
0
投票

您无法赶上杀戮会话。它会中断当前操作(尽可能多的操作-可能会导致某些低级操作引起问题),从而回滚未完成的事务。回滚完成后,将告知客户端已断开连接(假设客户端仍在),并且过程消失了。

kill session有几个变体会影响它们的顺序,但是您将无法从终止的会话中向任何表中插入任何内容。

唯一的例外可能是通过数据库链接或类似链接,实际上您同时有两个单独的会话/进程在进行。

© www.soinside.com 2019 - 2024. All rights reserved.