SQL stored procedures delete all object statements of a user

Source: Internet
Author: User
For an SQL statement that may be encountered during development, we use the SQL stored procedure to delete all objects under the user. If you need it, you can refer to it. It is very simple.

For an SQL statement that may be encountered during development, we use the SQL stored procedure to delete all objects under the user. If you need it, you can refer to it. It is very simple.

The Code is as follows:


Create or replace procedure drop_all as cursor cur_obj is
Uo. OBJECT_NAME, uo. OBJECT_TYPE
From user_objects uo
Where uo. OBJECT_NAME not in ('drop _ all ')
And uo. OBJECT_TYPE not in ('lob ');

/* Cursor cur_tablespace is
Select ut. TABLESPACE_NAME
From user_tablespaces ut
Where ut. TABLESPACE_NAME not in
('System', 'sysaux ', 'undotbs1', 'temp', 'users ');*/

V_obj_name user_objects.OBJECT_NAME % type;
V_obj_type user_objects.OBJECT_TYPE % type;
/* V_tablespaces_name user_tablespaces.TABLESPACE_NAME % type ;*/
SQL _str1 varchar2 (2000 );
/* SQL _str2 varchar2 (2000 );*/
Begin
Open cur_obj;
Loop
Fetch cur_obj
Into v_obj_name, v_obj_type;
Exit when cur_obj % notfound;
SQL _str1: = 'drop' | v_obj_type | ''| v_obj_name;
Execute immediate SQL _str1;
End loop;
Close cur_obj;
/* Open cur_tablespace;
Loop
Fetch cur_tablespace
Into v_tablespaces_name;
Exit when cur_tablespace % notfound;
SQL _str2: = 'drop tablespace' | v_tablespaces_name |
'Encuding CONTENTS ';
Execute immediate SQL _str2;
End loop;
Close cur_tablespace ;*/
End drop_all;

This stored procedure can delete almost all objects under the user. Release the items in the comment to delete the tablespace. This process cannot be rolled back and never used in the production environment or useful environment. I am not responsible for the results of this process.

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.