1. 程式人生 > >查詢oracle下沒有時間戳的表中的記錄插入時間

查詢oracle下沒有時間戳的表中的記錄插入時間

近日線上系統出現一個表中資料重複的問題,但是根據業務流程來講不可能出現該種情況,只可惜該表中沒有加入時間戳,所以問題變的不好查。

所以網上查了相關資料,發現可以用以下的語句查詢:

select t.seq_id,t.hall_id,to_char(scn_to_timestamp(ORA_ROWSCN),'yyyy-mm-dd hh24:mi:ss:ff8') insert_time from dim_geog_a t;

查詢結構如下圖所示:

但是此語句去查詢的是偶該表中相關記錄不能超過5天否則會報 不是有效的系統更改號的錯誤。

說明如下:

Cause

This is expected behavior as the SCN must be no older than 5 days as part of the current flashback database
features.

Currently, the flashback query feature keeps track of times up to a
maximum of 5 days. This period reflects server uptime, not wall-clock
time. You must record the SCN yourself at the time of interest, such as
before doing a DELETE.

我們可以通過如下語句查詢每條記錄的rowscn。

SELECT --deptno,
        --dname,loc,
        dbms_rowid.rowid_block_number(ROWID) blockno,
        ora_rowscn
FROM dim_geog_a;

select * from dim_geog_a as of scn 74757285358;

網上相關資料說能夠建表時加引數知曉行級的scn資訊,但是我查詢不可行()即統一時間內插入的是一樣的,只有間隔一點時間才不一樣。

預設情況下,每行記錄的ORA_ROWSCN是基於Block的,這樣是不準確的,除非在建表的時候執行開啟行級跟蹤(create table … rowdependencies),這樣就會是在行級記錄scn。

待得到答案後再更新。