How Does Oracle batch clear multiple tables and retain the table structure.

Source: Internet
Author: User

More than 400 tables in the Test Database need to be cleared repeatedly for testing. I can only use one entry in PL/SQL
Truncate Table1;
Truncate Table2;
Truncate table3;
Truncate table4;
......
Only one execution can be selected at a time. If multiple execution items are selected, an error can be returned. If you want to write a stored procedure or batch processing, You can execute the task when clearing the task.

 

Begin
For C in (select T. constraint_name, T. table_name
From user_constraints t
Where T. constraint_type = 'R') loop
Execute immediate 'alter table' | C. table_name | 'Disable constraint' | C. constraint_name;
End loop;
For C1 in (select table_name from user_tables) loop
Execute immediate 'truncate table' | c1.table _ name;
End loop;
For C2 in (select T. constraint_name, T. table_name
From user_constraints t
Where T. constraint_type = 'R') loop
Execute immediate 'alter table' | c2.table _ name | 'Enable constraint' | c2.constraint _ name;
End loop;

End;

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.