MYSQL養成記-MYSQL基礎增強(Myql函數)

來源:互聯網
上載者:User

標籤:

MYSQL基礎增強(Myql函數)在這裡只介紹一些常用的,比較新穎的:字串函數:

 

CONCAT://字串串連函數
mysql> SELECT CONCAT(‘My‘, ‘S‘, ‘QL‘); -> ‘MySQL‘mysql> SELECT CONCAT(‘My‘, NULL, ‘QL‘);//與null串連會變null -> NULLmysql> SELECT CONCAT(14.3); -> ‘14.3‘
CONCAT_WS://含分隔字元的字串串連
mysql> SELECT CONCAT_WS(‘,‘,‘First name‘,‘Second name‘,‘Last Name‘); -> ‘First name,Second name,Last Name‘mysql> SELECT CONCAT_WS(‘,‘,‘First name‘,NULL,‘Last Name‘); -> ‘First name,Last Name‘

LOWER(str)/UPPER(str) //把字串轉換成小寫或者大寫
LEFT(str,x)/RIGHT(str,x) //返回字串最左邊的x個字元和最右邊的x個字元
SUBSTRING(str,x,y) //對給定字串進行提取x位置往後的y個字元
mysql> select substring(‘I love mysql‘,8,4);
-> ‘mysql’
find_in_set(str,strList)//實現如果字串str在由N子串組成的表strlist之中,返回一個1到N的值。strList是被‘,’分隔的字串組成的。
例1:
create table books(
    bookid int primary key not null auto_increment

comment ‘使用者id‘,
    bookname varchar(50) not null,
    sort varchar(100)    
);
insert into books(bookid,bookname,sort) values
(1,‘大學英語‘,‘english,teach‘),
(2,‘C語言‘,‘language,c,old‘),
(3,‘高等數學‘,‘teach,olding‘);
select bookid,bookname from books where find_in_set(‘teach‘,sort);//其中sort是book表的列
mysql> SELECT LENGTH(‘text‘);//返回str的長度        -> 4



 

 

 

 

 

 

 

相關網址:

Mysql5.7函數地址:http://dev.mysql.com/doc/refman/5.7/en/func-op-summary-ref.html
Mysql5.x手冊 http://doc.mysql.cn/
Mysql官網 http://dev.mysql.com/
Mysql5.7參考手冊 http://dev.mysql.com/doc/refman/5.7/en/
其他參考手冊
CSDN-Mysql知識庫

author: liuning

MYSQL養成記-MYSQL基礎增強(Myql函數)

聯繫我們

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