Is there an automatic modification time stamp type for Oracle columns?

前端 未结 6 2125
臣服心动
臣服心动 2020-12-15 05:46

Is there a way to create a timestamp column in Oracle that automatically stores a timestamp of when the record has changed ?

6条回答
  •  天涯浪人
    2020-12-15 06:12

    You can get very close to this by querying ORA_ROWSCN: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns007.htm#sthref825

    This is more accurate if you created the table with the ROWDEPENDENCIES option.

    It actually logs the commit time for the record ...

    drop table tester 
    /
    
    create table tester (col1 number, col2 timestamp)
    rowdependencies
    /
    
    insert into tester values (1, systimestamp)
    /
    
    (approximate five second pause)
    
    commit
    /
    
    select t.ora_rowscn,
           SCN_TO_TIMESTAMP(t.ora_rowscn),
           t.col1,
           t.col2
    from   tester t
    /
    
    ORA_ROWSCN             SCN_TO_TIMESTAMP(T.ORA_ROWSCN) COL1                   COL2
    ---------------------- ------------------------------ ---------------------- -------------------------
    9104916600628          2009-10-26 09.26.38.000000000  1                      2009-10-26 09.26.35.109848000 
    

提交回复
热议问题