MySQL字元函數

來源:互聯網
上載者:User

標籤:img   刪除   blog   指定   結果   rom   長度   color   ges   

1.concat

 select concat(first_name,last_name) as full_name from string_test;

concat就是將多個字串串連起來,其中可以指定分隔字元(其實就是將字串‘ - ‘原樣輸出,達到一種假的分隔效果),如下:

select concat(first_name,‘-‘,last_name) as full_name from string_test;

2.concat_ws

 select concat_ws(‘-‘,first_name,last_name) as full_name from string_test;

注意:concat_ws的分隔字元是在第一個參數,它與concat有什麼不同?如下:

 select concat("|","A","B","C");

 

用concat_ws能讓每個單詞之間都存在分隔字元,達到真正的分隔效果,我們來看看concat:

select concat("|","A","B","C");

3.format()

 

select format(19986.78,1);

 

format接受兩個參數,第一個參數表示要格式化的數,第二個參數表示保留小數點的位元,其中會按照四捨五入保留有效數字。

select format(19986.78,2);

 

3.lower()

 

select lower(‘MYSQL‘);

 

lower()函數就是將字串轉換為小寫,上面的代碼執行結果如下:

3.upper()

效果與lower相反

4.left()

擷取字串左側的字元,接受兩個參數,第一個參數是要擷取的母串,第二個參數是擷取的長度,如下:

select left(‘mysql‘,2);

上面的函數表達的意思是:從mysql的左側擷取長度為2的字串。

5.right()

擷取右側的字串,與left的用法一樣。

6.length()

擷取字串的長度

select length(‘mysql‘);

7.ltrim()

刪除前置空格

8.rtrim()

刪除後續空格

9.trim()

刪除前置和後續空格

如果一個字串是這樣的===>"???MySQL????"

那麼怎麼刪除前置問號和後續問號呢?如下:

刪除前置問號:

select trim(leading "?" from "???MySQL????");

 

leading表示的就是前置的意思。

刪除後續問號: 

 select trim(trailing "?" from "???MySQL????");

刪除所有問號:

select trim(both "?" from "???MySQL????");

 

MySQL字元函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.