oracle資料庫函數整理

來源:互聯網
上載者:User

標籤:translate   常用   div   輸出   init   strong   bit   oracle   acl   

1.字元類

lpad(str1,length,str2)

lpad函數從左邊對字串使用指定的字元進行填充。從其字面意思也可以理解,l是left的簡寫,pad是填充的意思,所以lpad就是從左邊填充的意思。

舉例:select lpad(1,5,‘x‘) from dual; 輸出結果:xxxx1

rpad(str1,length,str2)

lpad函數從右邊對字串使用指定的字元進行填充。從其字面意思也可以理解,r是right的簡寫,pad是填充的意思,所以lpad就是從右邊填充的意思。

舉例:select rpad(1,5,‘x‘) from dual; 輸出結果:1xxxx

upper(str)

將當前字串全部轉換為大寫

lower(str)

將當前字串全部轉換為小寫

initcap(str)

將第一個字元變成大寫,其他字元變成小寫

舉例:select initcap(‘hEllo wOrld‘) from dual; 輸出結果:Hello World

replace(字串1,字串2,字串3)

將字串1中所有的字串2,替換成字串3

舉例:select replace(‘hEllo world‘,‘hE‘,‘He‘) from dual; 輸出結果:Hello world

translate(char, from, to)

將from中的字元轉換為to中與之位置對應的字元,若to中找不到與之對應的字元,傳回值中的該字元將會被刪除

舉例:select translate(‘1ello 2orldc‘,‘12c‘,‘HW‘) from dual;輸出結果:Hello World

bitand(ex1,ex2)

不常用,返回兩個數值型數值在按位進行AND 運算後的結果;如果 ex1 和 ex2的位都是 1,相應的結果位就是 1;否則相應的結果位是 0 concat(char1,char2)將char1與char2字串拼接起來 wmsys.wm_concat將所有查詢結果的列以“,”拼接起來 2.日期類 to_char(date,char)日期轉字元舉例:select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss‘) from dual; 輸出結果:2017-07-31 17:16:14 to_date(char,date)字元轉日期舉例:select to_date(‘2017-07-31 17:16:14‘,‘yyyy-mm-dd hh24:mi:ss‘) from dual; 輸出結果:2017/7/31 17:16:14

select to_char(sysdate, ‘yyyy‘) as nowYear from dual; --擷取時間的年
select to_char(sysdate, ‘mm‘) as nowMonth from dual; --擷取時間的月
select to_char(sysdate, ‘dd‘) as nowDay from dual; --擷取時間的日
select to_char(sysdate, ‘hh24‘) as nowHour from dual; --擷取時間的時
select to_char(sysdate, ‘mi‘) as nowMinute from dual; --擷取時間的分
select to_char(sysdate, ‘ss‘) as nowSecond from dual; --擷取時間的秒
select to_char(to_date(‘2017-07-31‘,‘yyyy-mm-dd‘),‘day‘) from dual; --擷取某天是星期幾

3.彙總函式 avg()平均值 max()最大值 min()最小值 sum()求和 count()統計 4.條件判斷 nvl(a,b)如果前面的a的值為null那麼返回的值為後面的b nvl2(a,b,c)如果a為null,則結果為b,否則結果為c decode(欄位,條件1,值1,條件2,值2,…值n)如果欄位滿足條件1,那麼取值1,以此類推,最後傳回值n 

 

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.