自學(xué)MySql內(nèi)置函數(shù)知識點(diǎn)總結(jié)
字符串函數(shù)
查看字符的ascii碼值ascii(str),str是空串時返回0
select ascii('a');
查看ascii碼值對應(yīng)的字符char(數(shù)字)
select char(97);
拼接字符串concat(str1,str2...)
select concat(12,34,'ab');
包含字符個數(shù)length(str)
select length('abc');
截取字符串
- left(str,len)返回字符串str的左端len個字符
- right(str,len)返回字符串str的右端len個字符
- substring(str,pos,len)返回字符串str的位置pos起len個字符
select substring('abc123',2,3);
去除空格
ltrim(str)返回刪除了左空格的字符串str
rtrim(str)返回刪除了右空格的字符串str
trim([方向 remstr from str)返回從某側(cè)刪除remstr后的字符串str,方向詞包括both、leading、trailing,表示兩側(cè)、左、右
select trim(' bar '); select trim(leading 'x' FROM 'xxxbarxxx'); select trim(both 'x' FROM 'xxxbarxxx'); select trim(trailing 'x' FROM 'xxxbarxxx'); SELECT TRIM(LEADING ' ' FROM ' my ');
返回由n個空格字符組成的一個字符串space(n)
select space(10);
替換字符串replace(str,from_str,to_str)
select replace('abc123','123','def');
大小寫轉(zhuǎn)換,函數(shù)如下
- lower(str)
- upper(str)
select lower('aBcD');
數(shù)學(xué)函數(shù)
求絕對值abs(n)
select abs(-32);
求m除以n的余數(shù)mod(m,n),同運(yùn)算符%
select mod(10,3); select 10%3;
地板floor(n),表示不大于n的最大整數(shù)
select floor(2.3);
天花板ceiling(n),表示不小于n的最大整數(shù)
select ceiling(2.3);
求四舍五入值round(n,d),n表示原數(shù),d表示小數(shù)位置,默認(rèn)為0
select round(1.6);
求x的y次冪pow(x,y)
select pow(2,3);
獲取圓周率PI()
select PI();
隨機(jī)數(shù)rand(),值為0-1.0的浮點(diǎn)數(shù)
select rand();
還有其它很多三角函數(shù),使用時可以查詢文檔
日期時間函數(shù)
獲取子值,語法如下
- year(date)返回date的年份(范圍在1000到9999)
- month(date)返回date中的月份數(shù)值
- day(date)返回date中的日期數(shù)值
- hour(time)返回time的小時數(shù)(范圍是0到23)
- minute(time)返回time的分鐘數(shù)(范圍是0到59)
- second(time)返回time的秒數(shù)(范圍是0到59)
select year('2016-12-21');
日期計(jì)算,使用+-運(yùn)算符,數(shù)字后面的關(guān)鍵字為year、month、day、hour、minute、second
select '2016-12-21'+interval 1 day;
日期格式化date_format(date,format),format參數(shù)可用的值如下
獲取年%Y,返回4位的整數(shù)
* 獲取年%y,返回2位的整數(shù)
* 獲取月%m,值為1-12的整數(shù)
獲取日%d,返回整數(shù)
* 獲取時%H,值為0-23的整數(shù)
* 獲取時%h,值為1-12的整數(shù)
* 獲取分%i,值為0-59的整數(shù)
* 獲取秒%s,值為0-59的整數(shù)
select date_format('2016-12-21','%Y %m %d');
當(dāng)前日期current_date()
select current_date();
當(dāng)前時間current_time()
select current_time();
當(dāng)前日期時間now()
select now();
以上就是本次介紹的全部相關(guān)知識點(diǎn),如果大家有任何需要補(bǔ)充的地方可以聯(lián)系腳本之家的小編。
相關(guān)文章
利用Prometheus與Grafana對Mysql服務(wù)器的性能監(jiān)控詳解
Prometheus是源于 Google Borgmon的一個開源監(jiān)控系統(tǒng),用 Golang開發(fā)。被很多人稱為下一代監(jiān)控系統(tǒng)。Grafana是一個開源的圖表可視化系統(tǒng),簡單說圖表配置比較方便、生成的圖表比較漂亮。下面就介紹了利用Prometheus與Grafana對Mysql服務(wù)器性能監(jiān)控的方法。2017-03-03mysql數(shù)據(jù)庫基礎(chǔ)知識點(diǎn)與操作小結(jié)
這篇文章主要介紹了mysql數(shù)據(jù)庫基礎(chǔ)知識點(diǎn)與操作,總結(jié)分析了mysql數(shù)據(jù)庫修改數(shù)據(jù)表、增刪改查及數(shù)據(jù)庫函數(shù)基本功能,需要的朋友可以參考下2020-01-01mysql下為數(shù)據(jù)庫設(shè)置交叉權(quán)限的方法
由于 SupeSite 需要調(diào)用 Discuz! 和 UCHome 的數(shù)據(jù),所以如果它們不安裝在同一個數(shù)據(jù)庫,SupeSite 的數(shù)據(jù)庫用戶必須要對 Discuz! 和 UCHome 的數(shù)據(jù)庫有讀取、修改、刪除等權(quán)限。2011-07-07