0

I'm missing something in my query. I want to select all tables from dba_tables except a list of tables.

For example, show all except HR.DEPT, SCHEMA.TAB

dba_tables:

OWNER TABLE_NAME
------ ----------
HR DEPT
HR TEST
SCHEMA TAB
SCHEMA NAMES
TEM TBA

Result after query:

OWNER TABLE_NAME
------ ----------
HR TEST
SCHEMA NAMES
TEM TBA

Query I tried:

select owner, table_name from dba_tables
where (owner != 'HR' and table_name != 'DEPT' ) OR (owner != 'SCHEMA' and table_name != 'TAB' )
asked Mar 27, 2019 at 11:45

2 Answers 2

4
select owner, table_name from dba_tables
where (owner, table_name) not in (('HR', 'DEPT'), ('SCHEMA', 'TAB'));
answered Mar 27, 2019 at 11:53
0

The problem is your OR. When the table is DEPT of the HR schema, the first AND condition is false, but the 2nd AND condition is true, thus the OR results as true and no row is filtered.

Try with NOT + AND:

select 
 owner, 
 table_name 
from 
 dba_tables
where 
 NOT (owner = 'HR' and table_name = 'DEPT') AND 
 NOT (owner = 'SCHEMA' and table_name = 'TAB')
answered Mar 27, 2019 at 11:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.