oracle中的not in問題

2022-03-23 04:38:34 字數 806 閱讀 8644

oracle中的not in問題

最近過程比較忙,沒日沒夜的,好久沒有時間寫部落格了,今天乙個特別詭異,特別蛋疼的問題糾結了好久,不得不寫個部落格了。

www.2cto.com  

[sql] 

select * from wlbtest3  

where (sname, sage) not in (select user_name,user_age  from wlbtest4)  

select * from wlbtest3  

where (sname||sage) not in (select user_name||user_age  from wlbtest4)  

大家覺得上邊兩句效果一樣嗎?

www.2cto.com  

你是認為一樣你就錯了!!!我開始也認為是一樣。工作時用到了這個,但資料總是不和邏輯。

最後終於讓我找到這個地方了:

[html] 

select * from wlbtest3  

where (sname, sage) not in (select user_name,''  from wlbtest4)  

上邊一句是什麼意思呢?不用猜了!!!

他的意思是匹配sname,但不匹配sage,和下邊的效果一樣。

[html] 

select * from wlbtest3  

where (sname) not in (select user_name from wlbtest4)  

所以當user_age的值為空時,就會產生意想不到的問題。所以建議用「||」方式。

ORACLE中NOT IN 的替代

典型的查詢方式為 select title from bookshelf where title not in select title from bookshelf checkout order by title 如果bookshelf checkout很大的話,速度可能會很慢,因為oracle會...

ORACLE中NOT IN 的替代

查詢哪些書沒有借出?典型的查詢方式為 select title from bookshelf where title not in select title from bookshelf checkout order by title 如果bookshelf checkout很大的話,速度可能會很慢...

SQL 中 not in 查詢不到資料問題

在開發的過程中,遇到過not in 始終查詢不到資料問題 select from t customerinfo where customerid not in select customerid from t orderinfo 後來使用not exists查詢 select from t cust...