Tuesday, November 10, 2015

Oracle: quick AS OF demo

First, let's check our current SCN

    scott@orcl> select current_scn from v$database;
    current_scn
    -----------
    7559499070893

And see how many rows we have in table FOO

    scott@orcl> select count(*) from foo;
    count(*)
    --------
          33

Delete everything from FOO

    scott@orcl> delete from foo;
    (33 rows, 0.011 sec)

    scott@orcl> select count(*) from foo;
    count(*)
    --------
           0

What's our SCN now?

    scott@orcl> select current_scn from v$database;
    current_scn
    -----------
    7559499071397

What was the count as of yesterday?

    scott@orcl> select count(*) from foo as of timestamp sysdate-1;
    count(*)
    --------
          33

And as of the SCN at the start of our session?

    (1 rows, 0.010 sec)
    scott@orcl> select count(*) from foo as of scn 7559499070893;
    count(*)
    --------
          33

blogodex = {"toc" : "Oracle SCN", "idx" : ["Oracle", "SCN", "System Change Number", "as of"]};

No comments: