05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 1 ■ DEVELOPING SUCCESSFUL ORACLE APPLICATIONS 23<br />

scott@ORA10G> select count(*) from emp AS OF SCN :scn;<br />

COUNT(*)<br />

----------<br />

14<br />

Further, this capability works across transactional boundaries. We can even query the<br />

same object “as of two points in time” in the same query! That opens some interesting opportunities<br />

indeed:<br />

scott@ORA10G> commit;<br />

Commit complete.<br />

scott@ORA10G> select *<br />

2 from (select count(*) from emp),<br />

3 (select count(*) from emp as of scn :scn)<br />

4 /<br />

COUNT(*) COUNT(*)<br />

---------- ----------<br />

0 14<br />

If you are using <strong>Oracle</strong> 10g <strong>and</strong> above, you have a comm<strong>and</strong> called “flashback” that uses<br />

this underlying multi-versioning technology to allow you to return objects to the state they<br />

were in at some prior point in time. In this example, we can put EMP back the way it was before<br />

we deleted all of the information:<br />

scott@ORA10G> flashback table emp to scn :scn;<br />

Flashback complete.<br />

scott@ORA10G> select *<br />

2 from (select count(*) from emp),<br />

3 (select count(*) from emp as of scn :scn)<br />

4 /<br />

COUNT(*) COUNT(*)<br />

---------- ----------<br />

14 14<br />

■Note If you receive the error “ORA-08189: cannot flashback the table because row movement is not<br />

enabled using the FLASHBACK comm<strong>and</strong>,” you must issue ALTER TABLE EMP ENABLE ROW MOVEMENT.<br />

This, in effect, gives <strong>Oracle</strong> the permission to change the rowid assigned to a row. In <strong>Oracle</strong>, when you insert<br />

a row, a rowid is assigned to it <strong>and</strong> that row will forever have that rowid. The flashback table process will<br />

perform a DELETE against EMP <strong>and</strong> reinsert the rows, hence assigning them a new rowid. You must allow<br />

<strong>Oracle</strong> to do this operation in order to flash back.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!