Use PL/SQL to quickly delete all table data under a user

Source: Internet
Author: User

In Oracle, if you want to delete a user's table data in multiple ways, we recommend a fast method to delete all the table data under the user, you can use plsql to quickly delete a file. The Code is as follows:

Declare
Cursor c_t is (select table_name from user_tables); -- declares a cursor
Table_name user_tables.table_name % type; -- declare a table name variable
Begin
Open c_t;
Loop-loop
Fetch c_t into table_name;
Exit when c_t % notfound;
Execute immediate 'delete from' | table_name; -- delete a dynamic SQL statement
End loop;
Close c_t;
End;

In Oracle, user_tables is a dictionary table that stores information about the user table. You can use a cursor to obtain information about the current user table stored in the dictionary table, then, the data in each table is deleted cyclically. It is very simple. This should be frequently encountered in the development process.

Rlwrap

SQLPLUS spool to dynamic Log File Name

Oracle SQLPLUS prompt settings

Accelerate SQL return by setting SQLPLUS ARRAYSIZE (row prefetch)

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.