Thanks for the question, marcelo.
Asked: February 15, 2016 - 2:38 pm UTC
Last updated: February 16, 2016 - 11:10 am UTC
Version: 11.2.0.4
Viewed 1000+ times
You Asked
I was trying to play with "update restart" and found this situation.
create or replace package pkg_array
as
g_cnt number;
end pkg_array;
/
create table t
as
select rownum object_id,object_name
from dba_objects
where rownum<=50000;
create or replace trigger trg_bef_upd_row_on_t
before update on t
for each row
begin
pkg_array.g_cnt := pkg_array.g_cnt + 1;
end;
/
begin
pkg_array.g_cnt := 0;
update t
set object_id = object_id + 1
where object_id > 0;
dbms_output.put_line( 'trigger count = ' || pkg_array.g_cnt );
end;
/
trigger count = 50007
Could you explain to me why the trigger is executed more than 50000 times if this is the only session modifying the table ?
and Chris said...
As Tom says in this thread:
https://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:11504247549852 the restart is done when:
a) consistent read (the search component of your modification) says "this row, when we started, was
one you were interested in"
b) the current read (get the row as of right now, we have to modify the CURRENT value) is done
c) a comparision of the current read to the consistent read says "the row was modified".
Precisely why this happened in your case doesn't really matter. You just need to be aware that it can happen! There doesn't have to be other sessions to cause this.
Is this answer out of date? If it is, please let us know via a Comment