Oracle中奇怪的【不等號】

來源:互聯網
上載者:User

標籤:

在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 testSELECT CONCAT(‘this is ‘,‘a test‘) from dual;   傳回值this a testSELECT ‘this is ‘||‘a test‘ from dual;           傳回值this a test
 分類: ORACLE

Oracle中奇怪的【不等號】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.