oracle常用函數

來源:互聯網
上載者:User

標籤:串連符   sni   star   snippet   sub   mat   osi   多個   關鍵字   

第一:去重    使用distinct關鍵字。

第二:補位函數 LPAD (左補位),RPAD(右補位)

          eg: 工資列不足15使用“$”左補足15位(  使用LPAD方法實現對工資列的左補位,SQL語句如下所示)

    SELECT ename, LPAD(sal, 15, ‘$‘) as "SALARY" FROM emp ;

第三:字串函數 使用 concat()  或使用 ||  串連符 。

           eg:select empname || ‘:‘ || sal from emp  使用 ||  更為直觀 。

第四:TRIM作用截去字串,經常用來去掉字串前後空格。

第五:SUBSTR()擷取字串的子串  INSTR(sourceString,destString,start,appearPosition)  或  instr(‘源字串‘ , ‘目標字串‘ ,‘開始位置‘,‘第幾次出現‘) 擷取子字串在原字串的位置  start和appearPosition都預設是1 。

           用法:substr(str,start,end),或 substr(str,start)  如果start=0則從首字元開始,如果start等於負數則從尾部開始。

                      instr(‘abcdefgh‘,‘de‘)  select instr(‘abcdefgh‘,‘de‘) position from dual;   返回  4     解釋:從1開始算 d排第四所以返回4

                      select instr(‘abcdefghbc‘,‘bc‘,3) position from dual;   返回 9  解釋:從第3個字元開始算起 第3個字元是c,所以從3開始以後的字串找尋找bc,返回9

                      select instr(‘qinyinglianqin‘,‘qin‘, 1, 2) position from dual;   返回12 解釋:從第1個字元開始,尋找第2次出現子串的位置

  substr()經常和 instr()  一塊使用   通過instr()擷取自古傳的位置  substr()  利用instr返回來的位置  做起始或結束位置

第六:nvl(expr1,expr2) 和 nvl2(expr1,expr2,expr3) 是空值函數

           nvl(expr1,expr2)  如果exp1是null  則取值exp2  exp2是實際值  exp1和exp2 可以是任何資料類型,但是exp1和exp2必須是相同的資料類型。

           eg:select ename,sal,common sal+nvl(common,o) as salary from emp

           nvl2(expr1,expr2,exp3) 判斷如果exp1不是空則返回exp2,如果exp1是空則返回exp3

           eg:select ename,sal,common nvl2(commom,sal+commom,sal) as salary from em

第七:分組函數 group by () having()   having()必須在group by()後使用

第八:order by 升序降序 (可以按字母、數字、日期) 預設是asc升序  降序必須表明 desc 如果對多個欄位用排序 那麼每個欄位必須表明是升序還是降序

 

 

                     

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.