2015-11-13 129 views
1

我有表TEST_TABLE有3列COL1(Number),COL2(Varchar),COL3(Date)。 我想在兩個不同的事務的匿名塊中查找以下查詢的結果。一個用於當前交易,另一個用於前一個交易。如何使用SCN做到這一點?使用ORA_ROWSCN查找當前和前一個事務

BEGIN 
    Select col3 into v_curr_date from test_table where col1=123; --Current 
    uncommitted Transaction 

    Select col3 into v_prev_date from test_table where col1=123; --How to 
    modify this query to find for immediately Previous committed Transaction. 

    END ; 
+1

我沒有看到用'SELECT ..INTO'語句提交的事務中的點。 –

回答

1

下面的一個會給你發生在桌子上的最新承諾日期。 SCN_TO_TIMESTAMP以一個數字作爲參數,該數字的計算結果爲系統更改編號(SCN),並返回與該SCN關聯的近似時間戳。所以相應地修改你的查詢。

 DECLARE 
    v_prev_date date; 
    BEGIN 
    Select SCN_TO_TIMESTAMP(ORA_ROWSCN) into v_prev_date 
    from test_table where col1=123; 
    dbms_output.put_line(v_prev_date ); 
    end; 
相關問題