查询dbms_flashback.get_system_change_number可以得到系统当前的scn号,但每隔三秒就会增加,可能是因为lgwr三秒触发的缘故吧。
验证过程如下正好是连续递增的。
/*set serverout on
declare
i number;
x number;
begin
for i in 1..10 loop
select dbms_flashback.get_system_change_number into x from dual;
dbms_output.put_line(x);
dbms_lock.sleep(3);
end loop;
end;
*/
4797288
4797289
4797290
4797291
4797292
4797293
4797294
4797295
4797296
而以下过程又有所不同。
SQL> set serverout on
SQL> declare
2 i number;
3 x number;
4 begin
5 for i in 1..10 loop
6 select current_scn into x from v$database;
7 dbms_output.put_line(x);
8 dbms_lock.sleep(3);
9 end loop;
10 end;
11 /
4832165
4832167
4832169
4832171
4832173
4832175
4832177
4832179
4832181
4832183
是每三秒递增两次。
记得我们的老鹰有篇文章讲
我们看到current_scn的查询会直接导致SCN的增进,而其他方式并不会。也就是说在这里的current_scn就像是一个Sequence一样,查询会导致增进。这也很好理解,v$database只能通过增进当前的SCN才能保证获得的SCN是Current的。可是如果不查询呢?这个值肯定是不会增长的。
所以你查询这个的话,除了scn本身自动增加,也会由于查询current_scn而再次增加,所以是两个。
[@more@]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/288166/viewspace-967572/
,如需转载,请注明出处,否则将追究法律责任。