简体   繁体   中英

Oracle Minus query

I have problem with Oracle minus query. If my query is like this

 select col1 from 
(select '1' col1 from dual
union
select '2' col1 from dual )
minus
select col1 from 
(select '1' col1 from dual
 );

Result is as expected 2 . But If I put a Semicolon after Query 1 as below

select col1 from 
(select '1' col1 from dual
union
select '2' col1 from dual );
minus
select col1 from 
(select '1' col1 from dual
 );

Result is 1 .Can anybody explain me why Result is like this. I am using PL/SQL Developer

When you put the semicolon after first select it means that the select is finished, there for you got two separated selects

first select is:

select col1 from 
(select '1' col1 from dual
union
select '2' col1 from dual );

and it returns 1 and 2

the second is:

minus
select col1 from 
(select '1' col1 from dual
);

minus haven't got any meaning in this part but the select can run and it returns 1

there for you just run your query from the second part and see 1 as your result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM