Du kan bruge union
for at bygge tabel over byer og derefter minus
operatør.
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
I stedet for union kan du bruge den foruddefinerede type odcivarchar2list
, som forkorter syntaks:
select column_value as city
from table(sys.odcivarchar2list('Dallas', 'Berlin', 'Cracow', 'Praha'))
minus
select city from address
... og i stedet for minus
Du kan bruge joins eller not in
eller not exists
.
Testdata og output af begge forespørgsler:
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