Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: PL/SQL: How to check if a table exists or not?

Re: PL/SQL: How to check if a table exists or not?

From: Tim Witort <trwNOSPAM_at_NOSPAMmedicalert.org>
Date: 1997/08/27
Message-ID: <3404B604.304F@NOSPAMmedicalert.org>#1/1

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.

If you want to know if the table exists IN THE CURRENT USER'S SCHEMA: SELECT
  DECODE(count(*),0,'F','T')
FROM
  user_tables
WHERE
  table_name = 'THE_TABLE_I_NEED';

If you don't care about who owns the table - just ANY table in the database with the name (user must have select privs on the dictionary tables):

SELECT
  DECODE(count(*),0,'F','T')
FROM
  sys.dba_tables
WHERE
  table_name = 'THE_TABLE_I_NEED';

Or the all-around solution where you know the owner explicitly:

SELECT
  DECODE(count(*),0,'F','T')
FROM
  sys.dba_tables
WHERE
  owner = 'OWNER_NAME'
  AND table_name = 'THE_TABLE_I_NEED';

Received on Wed Aug 27 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US