在Oracle中,不等號有三種:<>,!=,^=
例如:
select * from test where name<>'xn'。返回的結果是name不為xn,且name不空的記錄。但是這與我們想要得到的結果有出入,因為我們的目的是得到name為xn的全部記錄,當然這也包括name為空的記錄,所以這些寫SQL語句是有問題的。為了解決這個問題,我們可以采用以下兩種方案:
select * from test where instr(concat(name,'xx'),'xn') = 0 ; select * from test where nvl(name,'xx')<>'xn' ;
備注:null只能通過is null或者is not null來判斷,其它操作符與null操作都是false。
各數據庫中的字符串連接方法
1)MySQL:CONCAT()
2)Oracle:CONCAT(),||
3)SQL Server: +
例如:
SELECT 'this is '+'a test'; 返回值this a test SELECT CONCAT('this is ','a test') from dual; 返回值this a test SELECT 'this is '||'a test' from dual; 返回值this a test