Basic Oracle Tutorial: Restore deleted data on the current day

Source: Internet
Author: User

I deleted the database by mistake. The boss was very upset. I had to recover the database within 30 minutes. In a hurry, I wrote a stored procedure, which is suitable for deleting the table on the day of recovery without remembering the table name.

You only need to input the time of the current day, and then call it.

  1. The stored procedure is as follows:
  2. Create Or Replace ProcedureProc_databack (deletetimeInVarchar2)
  3. As
  4. -- Query information deleted on the current day and put it into the cursor
  5. CursorMycursorIs(SelectObject_nameFromRecyclebinWhereDroptimeLikeDeletetime );
  6. Temp_emp varchar2 (2000 );
  7. Vflash_back varchar2 (2000 );
  8. Begin
  9. OpenMycursor;
  10. Loop
  11. FetchMycursorIntoTemp_emp;
  12. ExitWhenMycursor % notfound;
  13. -- Build recovery statement
  14. Vflash_back: ='Flashback table "'| Temp_emp |'"To before drop';
  15. -- Restores the deleted table cyclically until all the tables are restored.
  16. ExecuteImmediate vflash_back;
  17. EndLoop;
  18. CloseMycursor;
  19. End;
  20. -- Call a stored procedure
  21. -- For example, if today is 2011-12-02, the statement is as follows:
  22. /*
  23. Declare
  24. TimeVarchar2 (20 );
  25. Begin
  26. Time: ='2017-12-2011';
  27. Proc_databack (Time);
  28. End;
  29. */

Related Article

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.