Application of the flash back function of Oracle 10g Query

Source: Internet
Author: User

InOracleIf the modification operation is submitted incorrectly,Then you want to view and modify the original value.,In this case, you can use the query to flash back.(Query flashback ).

    You can query the flash back based on a time value or a system change number.(SCN: System Change Number)Proceed,Database usageSCNTo track changes to the data.,Therefore, it can be used to flash back to a specific databaseSCNStatus.

     

    I.Perform the flash back operation,Need to useDBMS_FLASHBACKPackage,If you want to have this packageEXECUTEPermission,The following usesSysIdentity Logon,And authorize the userEXECUTEPermission:

    CONNECT SYS/P @ ssw0rdAS SYSDBA;

    GRANT EXECUTE ON SYS. DBMS_FLASHBACKTOUserName;

     

    II.Flash back of Time query

    1.RunSQLStatement fromProductsQuery the first five records,As follows::

    SELECTProduct_id, name, price,SYSDATE AS TIME

    FROMProducts

    WHEREProduct_id <= 5;

    2.Update record,As follows::

    SELECTProduct_id,NAME, Price,SYSDATE AS TIME

    FROMProducts

    WHEREProduct_id <= 5;

    3.RunDBMS_FLASHBACK.ENABLE_AT_TIME ()Statement,Returns to a specific time.,As follows::

    DBMS_FLASHBACK.ENABLE_AT_TIME (SYSDATE-10/1440 );

    Flash back10Minutes ago(24 h * 60 mins = 1440 Mins ).

    4.Query now,The result is as follows:

    5.Disable Flashback EXECUTE DBMS_FLASHBACK.DISABLE ();Before you enable the flashback operation again,You must disable it first..These commands can only beSqlplusUsed in,InPl/SQLCannot be used.

     

    3..System Change number query flash back

    AccordingSCNThe flash back operation is more accurate than the time-based operation.,Because the database is usedSCNTo track database changes.

    1.Obtain the currentSCNCommand:

    VARIABLECurr_scnNUMBER;

    EXECUTE: Curr_scn: = DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER ();

    Print curr_scn

    2.Insert a record.

    SELECT*FROMProducts;

    INSERT INTOProducts (product_id, product_type_id,NAME,DESCRIPTION, Price)

    VALUES(13, 5, 'kobe Bryant ', 'No. 24', '24. 00 ');

    SELECT*

    FROMProducts

    WHEREProduct_id = 13;

    3.PassDBMS_FLASHBACK.ENABLE_AT_SYSTEM_CHANGE_NUMBER ()The statement can return to thisSCNStatus,OneSCNParameters.

    EXECUTE DBMS_FLASHBACK.ENABLE_AT_SYSTEM_CHANGE_NUMBER (: curr_scn );

    4.Query the inserted data,No record.

    SELECT*

    FROMProducts

    WHEREProduct_id = 13;

    5.Disable Flashback: EXECUTE DBMS_FLASHBACK.DISABLE ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.