Oracle
 sql >> Database >  >> RDS >> Oracle

Trova i dati mancanti passati a SQL nella clausola

Puoi usare union per costruire la tabella delle città e poi minus operatore.

select 'Dallas' as city from dual union all 
select 'Berlin' as city from dual union all 
select 'Cracow' as city from dual union all 
select 'Praha'  as city from dual  
minus
select city from address

Invece di union puoi usare il tipo predefinito odcivarchar2list , che accorcia la sintassi:

select column_value as city 
  from table(sys.odcivarchar2list('Dallas', 'Berlin', 'Cracow', 'Praha'))
minus
select city from address

... e invece di minus Puoi usare join o not in o not exists .

Testare i dati e l'output di entrambe le query:

create table address (id number, city varchar2(10));
insert into address values (1, 'Rome');
insert into address values (2, 'Dallas');
insert into address values (3, 'Cracow');
insert into address values (4, 'Moscow');
insert into address values (5, 'Liverpool');
insert into address values (6, 'Cracow');
insert into address values (7, 'Seoul');

CITY
------------
Berlin
Praha