Drop table and purge in Oracle Database

Source: Internet
Author: User

Actual Example:

Create or replace procedure pro_droptable IS

Cursor cur is

Select table_name from user_tables where table_name like 'temptable % ';

Drop_ SQL varchar2 (1000 );

Table_number number;

BEGIN

Select count (*) INTO table_number from USER_TABLES WHERE TABLE_NAME LIKE 'tem % ';

For tbname in cur loop

Begin

If table_number <50 then

Exit;

End if;

Drop_ SQL: = 'drop table' | tbname. table_name | 'purge ';

Execute immediate drop_ SQL;

Table_number: = table_number-1;

End;

End loop;

END pro_droptable;

Explanation:

The drop table is placed in the recycle bin (user_recyclebin) instead of deleted directly. In this way, the table information in the recycle bin can be restored or completely cleared.
1. query the recycle bin user_recyclebin to obtain the information of the table to be deleted, and then use the statement
Flashback table <user_recyclebin.object_name or user_recyclebin.original_name> to before drop [rename to <new_table_name>];
Restore the table in the recycle bin to the original name or specify a new name. data in the table is not lost.
To completely delete a table, use the following statement: drop table <table_name> purge;
2. clear information in the recycle bin.
Clear the specified table: purge table <table_name>;
Clear the recycle bin of the current user: purge recyclebin;
Clear the recycle bin of all users: purge dba_recyclebin;


Example 2:

Create or replace procedure pro_clean_recycle IS

-- TmpVar NUMBER;

Clean_recycle_ SQL varchar2 (1000 );

BEGIN

-- Purge recyclebin;

Clean_recycle_ SQL: = 'purge recyclebin ';

Execute immediate clean_recycle_ SQL;

END pro_clean_recycle;

For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12

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.