Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete all tables under the user by Oracle

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how Oracle deletes all the tables under users. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

0. The most straightforward way:

Log in to Oracle with sys as sysdba first

> sql shutdown

> sql startup

Drop user username cascade

Create a new user

1 、

Select 'Drop table' | | table_name | |';'

From all_tables

User name to be deleted by where owner=' (uppercase)'

2 、

Delete all tables

Take user test as an example

For example:

Declare

Cursor cur1 is select table_name from dba_tables where owner='TEST'

Begin

For cur2 in cur1 loop

Execute immediate 'drop table test.' | | cur2.table_name

End loop

End

3. This deletes all objects of the current user (tables, views, triggers, stored procedures, functions)

Never tried.

DECLARE

TYPE name_list IS TABLE OF VARCHAR2 (40)

TYPE type_list IS TABLE OF VARCHAR2 (20)

Tab_name name_list:=name_list ()

Tab_type type_list:=type_list ()

Sql_str VARCHAR2 (500)

BEGIN

Sql_str: = 'select uo.object_name,uo.object_type from user_objects uo where uo.object_type not in (' 'INDEX'',''LOB'') order by uo.object_type desc'

EXECUTE IMMEDIATE sql_str BULK COLLECT INTO tab_name,tab_type

FOR i IN Tab_name.FIRST.. Tab_name.LAST LOOP

Sql_str: = 'DROP' | | Tab_type (I) | |''| | Tab_name (I)

EXECUTE IMMEDIATE sql_str

END LOOP

END

This is the end of the article on "how to delete all the tables under the Oracle". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report