Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi experts
i want to create 3 to 4 table in a loop in many diffrent locations but in some locations the table exist and gives the exception already exist so is there any command like while creating function CREATE OR REPLACE etc i have tried DROP TABLE IF EXIST TABLENAME but not working...
any suggessions....
Posted
Updated 29-May-13 6:12am
v4
Comments
Hi Basmeh Awad,

Please accept my answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...

Thanks,
Tadit

Please follow the below solutions, they might help you.

1. Oracle: If Table Exists[^].
2. Oracle drop table if exists[^].
 
Share this answer
 
if you want to check table exist or not then query should like below...
SQL
select count(*)
from all_objects
where object_type in ('TABLE','VIEW')
and object_name = 'your_table_name';

OR...
SQL
DECLARE tbl_exist  PLS_INTEGER;

BEGIN
select count(*) into tbl_exist from user_tables where table_name = 'mytable';
if tbl_exist = 1 then
    execute immediate 'drop table mytable';
end if;

END;
--your create table query...

Note: when table created with double-quote then it's case sensetive name so in that case your_table_name should be in same case

Happy Coding!
:)
 
Share this answer
 
v2
Comments
Basmeh Awad 29-May-13 6:21am    
if i will write delete first and if table will not present it will raise an exception.."invalid table name"..i already mentioned "in some locations"
Aarti Meswania 29-May-13 6:26am    
see updated soulution...
Basmeh Awad 29-May-13 6:43am    
tried second one..."procedure successfully completed" but table is still there
Aarti Meswania 29-May-13 7:06am    
have you read note?
about case-sensetiveness of tablename?
CHill60 29-May-13 11:38am    
If it's not case sensitivity that's the problem then it may be that you are not the owner of the table and the select from user_tables will return 0 ... in which case try using select count(*) into tbl_exist from all_tables where table_name='mytable'; instead

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900