查看字符的ascii碼值ascii(str),str是空串時返回0函數
select ascii('a');
查看ascii碼值對應的字符char(數字)spa
select char(97);
拼接字符串concat(str1,str2...)code
select concat(12,34,'ab');
包含字符個數length(str)orm
select length('abc');
截取字符串blog
select substring('abc123',2,3);
去除空格ci
select trim(' bar '); select trim(leading 'x' FROM 'xxxbarxxx'); select trim(both 'x' FROM 'xxxbarxxx'); select trim(trailing 'x' FROM 'xxxbarxxx');
返回由n個空格字符組成的一個字符串space(n)rem
select space(10);
替換字符串replace(str,from_str,to_str)字符串
select replace('abc123','123','def');
大小寫轉換,函數以下數學
select lower('aBcD');
求絕對值abs(n)string
select abs(-32);
求m除以n的餘數mod(m,n),同運算符%
select mod(10,3); select 10%3;
地板floor(n),表示不大於n的最大整數
select floor(2.3);
天花板ceiling(n),表示不小於n的最大整數
select ceiling(2.3);
求四捨五入值round(n,d),n表示原數,d表示小數位置,默認爲0
select round(1.6);
求x的y次冪pow(x,y)
select pow(2,3);
獲取圓周率PI()
select PI();
隨機數rand(),值爲0-1.0的浮點數
select rand();
3、日期時間函數
獲取子值,語法以下
select year('2016-12-21');
日期計算,使用+-運算符,數字後面的關鍵字爲year、month、day、hour、minute、second
select '2016-12-21'+interval 1 day;
日期格式化date_format(date,format),format參數可用的值以下
select date_format('2016-12-21','%Y %m %d');
當前日期current_date()
select current_date();
當前時間current_time()
select current_time();
當前日期時間now()
select now();