Oracle 常見函數使用匯總

來源:互聯網
上載者:User

標籤:


INSTR
用法:INSTR(string,subString,position,ocurrence)
解釋:string:源字串
      subString:要尋找的子字串
      position:尋找的開始位置.若起始位置為0,傳回值為0;當起始位置為負數的時候,從右邊開始尋找。
      ocurrence:源字串中第幾次出現的子字串

  返回找到的位置(字串下標是從0開始,如果尋找到),如果找不到則返回0. 預設尋找順序為從左至右。

SELECT INSTR(‘CORPORATE FLOOR‘, ‘OR‘, 0, 1) FROM DUAL;  傳回值為0SELECT INSTR(‘CORPORATE FLOOR‘, ‘OR‘, 2, 1) FROM DUAL;  傳回值為2SELECT INSTR(‘CORPORATE FLOOR‘, ‘OR‘, 2, 2) FROM DUAL;  傳回值為5SELECT INSTR(‘CORPORATE FLOOR‘, ‘OR‘, -1, 1) FROM DUAL; 傳回值為14SELECT INSTR(‘CORPORATE FLOOR‘, ‘OR‘, -5, 1) FROM DUAL; 傳回值為5



SUBSTR
用法:SUBSTR(string,start_position,[length] ) 求子字串,返回字串
解釋:string 元字串
       start_position   開始位置(從0開始)
       length 可選項,子字串的個數

SELECT SUBSTR(‘This is a test‘, 0, 2) value from dual;  傳回值ThSELECT SUBSTR(‘This is a test‘, 1, 2) value from dual;  傳回值HiSELECT SUBSTR(‘This is a test‘, -1, 2) value from dual; 傳回值tSELECT SUBSTR(‘This is a test‘, -2, 2) value from dual; 傳回值st

NVL用法:NVL(eExpression1, eExpression2)

  從兩個運算式返回一個非 null 值。如果eExpression1的計算結果為null值,則 NVL( ) 返回eExpression2。如果eExpression1的計算結果不是null值,則返回eExpression1。eExpression1 和eExpression2可以是任意一種資料類型。如果eExpression1與eExpression2 的結果皆為 null值,則NVL( )返回NULL。

SELECT nvl(‘pos1‘,null) from dual; 傳回值為pos1SELECT nvl(null,‘pos2‘) from dual; 傳回值為pos1SELECT nvl(null,null) from dual;    傳回值為null

 http://www.cnblogs.com/ningvsban/p/3586218.html
http://www.cnblogs.com/qqzy168/archive/2013/05/28/3103085.html

在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

http://www.cnblogs.com/ningvsban/p/3586223.html


 

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.