Oracle deletes an instance of an existing table

Source: Internet
Author: User

SQL code Copy codeThe Code is as follows: select count (*) from user_objects where object_name = upper (p_table_name );
Select count (*) from user_tables where table_name = upper (p_table_name );

Create or replace procedure p_drop_table_if_exist_v1 (
P_table_name in varchar2
) Is
V_count number (10 );
Begin
Select count (*)
Into v_count
From user_objects
Where object_name = upper (p_table_name );
If v_count> 0 then
Execute immediate 'drop table' | p_table_name | 'purge ';
End if;
Exception
When no_data_found then
Begin
Null;
End;
End;
/

Create or replace procedure p_drop_table_if_exist_v2 (
P_table_name in varchar2
) Is
V_table_name varchar2 (20 );
Begin
Select table_name
Into v_table_name
From user_tables
Where table_name = upper (p_table_name );
If length (v_table_name)> 0 then
Execute immediate 'drop table' | p_table_name | 'cascade constraints ';
End if;

Exception
When no_data_found then
Begin
Null;
End;
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.