mysql 函式彙總

2021-08-21 09:30:29 字數 1225 閱讀 2504

函式:

1、從左開始擷取字串

left(str, length)

說明:left(被擷取字段,擷取長度)

例:select left(content,200) as abstract from my_content_t

2、從右開始擷取字串

right(str, length)

說明:right(被擷取字段,擷取長度)

例:select right(content,200) as abstract from my_content_t

3、擷取字串

substring(str, pos)

substring(str, pos, length)

說明:substring(被擷取字段,從第幾位開始擷取)

substring(被擷取字段,從第幾位開始擷取,擷取長度)

例:select substring(content,5) as abstract from my_content_t

select substring(content,5,200) as abstract from my_content_t

(注:如果位數是負數 如-5 則是從後倒數字數,到字串結束或擷取的長度)

4、按關鍵字擷取字串

substring_index(str,delim,count)

說明:substring_index(被擷取字段,關鍵字,關鍵字出現的次數)

例:select substring_index(」blog.jb51.net」,」。」,2) as abstract from my_content_t

結果:blog.jb51

(注:如果關鍵字出現的次數是負數 如-2 則是從後倒數,到字串結束)

函式簡介:

substring(str,pos) , substring(str from pos)

substring(str,pos,len) , substring(str from pos for len)

不帶有len 引數的格式從字串str返回乙個子字串,起始於位置 pos。帶有len引數的格式從字串str返回乙個長度同len字元相同的子字串,起始於位置 pos。 使用 from的格式為標準 sql 語法。也可能對pos使用乙個負值。假若這樣,則子字串的位置起始於字串結尾的pos 字元,而不是字串的開頭位置。在以下格式的函式中可以對pos 使用乙個負值。

待續……

mysql內建函式彙總

mysql內建函式彙總 一.字串函式 select concat name,age is age from users insert str,x,y,insert 將字串x位置開始y個位置替換成insert select lower str upper str select from users w...

Mysql常用函式彙總

處理比較複雜的資料時,為了減少 可以使用一些mysql的一些函式,例如使用聚合函式做資料統計。如果expr1為true,返回expr2,否則返回expr3 如果expr1不是null,ifnull 返回expr1,否則它返回expr2。用於資料的四捨五入,round num 相當於round num...

mysql空間函式彙總

名稱 描述 1st startpoint linestring的起始點 2st endpoint linestring的終點 3st transform 變換幾何的座標 4st geohash 產生geohash值5 st longfromgeohash 從geohash值返回經度 6st latf...