2013年2月21日 星期四

腦力退化....null 值比較

今天在informix 做一個簡單的查詢時竟然對這個查詢結果懷疑了起來

create table test(col1 char(1) not null, col2 char(1));

insert into test values ('1' ,null);
insert into test values ('1' ,'1');

select * from test where col2 <> '1' ;

原本以為會回傳第一筆資料. 但卻回傳0筆.

以為是informix才會這樣,結果到sql server也是如此.

我的頭腦真是老化了,怎麼懷疑起這樣的結果呢.

null 與任何值比較應都是無法比的.

欄位值有null先轉型再比較唄

--tsql
select * from test where coalesce(col2,'') <> '1' ;

--informix
select * from test where nvl(col2,'') <> '1' ;


參考NULL 值說明

沒有留言:

張貼留言

pdf.js 無法顯示部份字

有個檔案在pdf viewer套件中無法顯示內容,但下載檔案後使用工具又可以正常顯示。 本來以為是套件版本太舊的原因,於是去下載pdf viewer套件 https://github.com/mozilla/pdf.js 更新後還是一樣。 覺得應是字型缺漏的問題,於是用PDF-X...