check if table exists oracle code example
Example 1: check if table exists oracle
BEGIN
SELECT COUNT(*)
INTO l_cnt
FROM dba_tables
WHERE owner = <<table owner>>
AND table_name = <<table name>>;
IF( l_cnt > 0 )
THEN
EXECUTE IMMEDIATE 'SELECT col1 FROM x'
BULK COLLECT INTO some_collection;
ELSE
SELECT 'table X does not exist'
INTO some_variable
FROM dual;
END IF;
END;
Example 2: check if table exists oracle
SELECT * FROM USER_TABLES WHERE TABLE_NAME = 'my_table';
SELECT * FROM ALL_TABLES WHERE OWNER = 'scheme_name' TABLE_NAME = 'my_table';
SELECT * FROM DBA_TABLES WHERE OWNER = 'scheme_name' TABLE_NAME = 'my_table';