據(jù)說EXCEL2007版本已經(jīng)提供了這種比對的功能,但無奈數(shù)據(jù)量太大,操作起來巨慢如牛,而WPS2009似乎還沒這個功能,于是導入數(shù)據(jù)庫中新建一個表存儲這些數(shù)據(jù)來比對。
開始寫了個SQL來查詢稅務有而ERP系統(tǒng)中沒有的數(shù)據(jù):
select * from tab_excel where taxcode not in
(select erpcode from tab_excel)
正常,然后反過來查ERP中存在而稅務系統(tǒng)中不存在的數(shù)據(jù):
select * from tab_excel where erpcode not in
(select taxcode from tab_excel)
返回0條數(shù)據(jù),很奇怪,然后馬上想到了是null的問題,taxcode必然存在值為null的記錄,oracle中和null比較的返回值是unkown,所以才無法匹配。
于是修改SQL語句如下:
select * from tab_excel tout where not exists
(select 1 from tab_excel where taxcode=tout.erpcode)
結果正常。
not in (...) 括號中的返回值不能存在null值,是Oracle SQL開發(fā)的一條鐵律,如果不能確定返回結果一定無null值,還是改寫為not esists吧。而且not in效率低下,一般不能用到索引,生產(chǎn)環(huán)境的程序最好不要使用。