Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: PL/SQL: How to check if a table exists or not?
Michael A. Casillas wrote:
>
> Yet another one:
>
> How can I check in PL/SQL if a table exists or not. Is there a built in
> function that can return TRUE or FALSE? I know the table name, I just
> want to know if it's there or if I have to create it. Thanks in
> advance.
>
> Michael Casillas
There are two ways : you can check user_tables as specified in the other replies, or you can use the exception handling :
DECLARE
NoTable Exception;
Pragma Exception_Init(NoTable,-942);
BEGIN
select *
from Some_Table
where ...;
EXCEPTION
when NoTable then
raise_application_error(-20000, 'Hey, Some_Table doesn''t exist');
END;
ORA-00942 is the Oracle error number for 'Table or view does not exist'.
This error message will also occur if the user can't access the table.
Marc Received on Thu Aug 28 1997 - 00:00:00 CDT
![]() |
![]() |