Oracle函數--合并,替換,拼接,截取,尋找

來源:互聯網
上載者:User

標籤:rom   cat   mysql   判斷   str   替換函數   ring   com   bsp   

1.合并函數 wm_concat(column)
wm_concat(列名),該函數可以把列值以“,”號分隔起來,並顯示成一行。如果列值是中文的,則選擇另一種方式: wm_concat(to_char(列名))

例如下面例子:

執行下面SQL:select id,wm_concat(to_char(name)) name from testTable group by id; 可得到下面結果

2.替換函數 replace(原欄位,“原欄位舊內容“,“原欄位新內容“,)

 執行下面SQL:select id,name,replace(num,‘10‘,‘5‘) num0 from testTable ;  可得到下面結果

3.拼接字串函數concat(字串1, 字串2

對於字串拼接,每一種資料庫都有戲相應方法-----MySQL: CONCAT()      Oracle: CONCAT(), ||      SQL Server: +

CONCAT() 的文法如下:CONCAT(字串1, 字串2, 字串3, ...): 將字串1、字串2、字串3,等字串聯在一起。但是,Oracle的CONCAT()只允許兩個參數,如要拼接多個參數則嵌套使用concat可實現,或者可以使用“||”來拼接 !!!

執行下面SQL:1)select name || ‘(‘ || num || ‘斤)‘ as str from testTable ; 

                      2)select concat(name, ‘(‘ || num || ‘斤)‘) as str from testTable ;可得到下面結果

4.截取字串函數substr(字串,截取開始位置,截取長度)

 執行下面SQL:  select substr(name,0,1) str from testTable; 可得到下面結果

5.尋找函數INSTR(string,subString,position,ocurrence)尋找字串位置

該函數可以用於模糊查詢以及判斷內含項目關聯性:

例如:1) select id,name ,num from testTable where instr(name,‘香蕉‘)>0;

等同於  select id,name ,num from testTable where name like ‘%香蕉%‘;

          2)  select id,name ,num from testTable where instr(‘123,香蕉‘,name)>0;

等同於  select id,name ,num from testTable where name in (‘123,香蕉‘);

 

 

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.