which way is appropriate to check table existence

Stefy

New Member
I want check a particular table existence in Oracle, which way is more general and appropriate, I have 2 ways listed below, the way 1 run fast if table existing, because it just run one sql[*]Handle the exception and get know it.\[code\]create or replace procedure get_id_only (id out number) asbeginexecute immediate 'SELECT id FROM TABLE_NAME where rownum = 1' into id;exception when others then if (sqlcode = -942) then SELECT id into id FROM my_another_table; else raise; end if;end;\[/code\][*]Check user table to see if it is existing.\[code\]create or replace procedure get_id_only (id out number) as count number;begin SELECT count(*) into count FROM user_tables WHERE table_name = 'TABLE_NAME'; if (count = 0) then SELECT id into id FROM my_another_table; return; end if; execute immediate 'SELECT id FROM TABLE_NAME where rownum = 1' into id;end;\[/code\]
 
Back
Top