且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Oracle 记录历史使用截至时间戳在一个范围内

更新时间:2022-03-19 06:01:27

是的,像这样:

SQL> select sal from emp where empno=7369;

       SAL
----------
      5800

SQL> update emp set sal = sal+100 where empno=7369;

1 row updated.

SQL> commit;

Commit complete.

SQL> update emp set sal = sal-100 where empno=7369;

1 row updated.      

SQL> commit;

Commit complete.

SQL> select empno, sal, versions_starttime,versions_xid
  2  from emp
  3  versions between timestamp sysdate-1 and sysdate
  4  where empno=7369;

     EMPNO        SAL VERSIONS_STARTTIME                                                          VERSIONS_XID
---------- ---------- --------------------------------------------------------------------------- --
      7369       5900 11-DEC-08 16.05.32                                                          0014001300002A74
      7369       5800 11-DEC-08 16.03.32                                                          000D002200012EB1
      7369       5800

请注意,您可以返回多远受 UNDO_RETENTION 参数限制,通常是几小时而不是几天.

Note that how far back you can go is limited by the UNDO_RETENTION parameter, and will typically be hours rather than days.