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;
/