MySQL常用函數(shù)
函數(shù) 用法 返回結(jié)果
(操作字符函數(shù))
concat() concat(t1,t2,...) 由t1,t2拼接而成的新字符串。
concat_ws() concat_ws(s,t1,t2,...) 由t1st2s拼接而成新字符串。
length() length(s) 字符串s的長(zhǎng)度。
left() left(s,x) 字符串s最左邊的x個(gè)字符。
right() right(s,y) 與上面函數(shù)相對(duì)應(yīng)。
trim() trim(s) 去掉字符串s首尾的空格。
upper() upper(s) 大寫。
lower() lower(s) 小寫。
replace() replace(s,t1,t2) 將字符串s中的t1替換為t2。
substring() substring(s,n,m) 截取s的字串,從第n個(gè)開始,取m個(gè)字符,n從1開始。
(操作數(shù)字函數(shù))abs() abs(n) n的絕對(duì)值。
ceiling() ceiling(n) 不小于n的整數(shù)。
floor() floor(n) n取整。
format() format(n,m) 格式化n,精度為m,每三位用逗號(hào)隔開。
mod() mod(n,m) n對(duì)m取模:n%m。
pow() pow(n,m) n的m次方。
rand() rand() 從0到1.0的隨機(jī)數(shù)。
round() round(n,m) 4舍5入(原文:n rounded to m decimal places)。
sqrt() sqrt(n) 對(duì)n開根。
(操作日期函數(shù))
(操作字符函數(shù))
concat() concat(t1,t2,...) 由t1,t2拼接而成的新字符串。
concat_ws() concat_ws(s,t1,t2,...) 由t1st2s拼接而成新字符串。
length() length(s) 字符串s的長(zhǎng)度。
left() left(s,x) 字符串s最左邊的x個(gè)字符。
right() right(s,y) 與上面函數(shù)相對(duì)應(yīng)。
trim() trim(s) 去掉字符串s首尾的空格。
upper() upper(s) 大寫。
lower() lower(s) 小寫。
replace() replace(s,t1,t2) 將字符串s中的t1替換為t2。
substring() substring(s,n,m) 截取s的字串,從第n個(gè)開始,取m個(gè)字符,n從1開始。
(操作數(shù)字函數(shù))
ceiling() ceiling(n) 不小于n的整數(shù)。
floor() floor(n) n取整。
format() format(n,m) 格式化n,精度為m,每三位用逗號(hào)隔開。
mod() mod(n,m) n對(duì)m取模:n%m。
pow() pow(n,m) n的m次方。
rand() rand() 從0到1.0的隨機(jī)數(shù)。
round() round(n,m) 4舍5入(原文:n rounded to m decimal places)。
sqrt() sqrt(n) 對(duì)n開根。
(操作日期函數(shù))
date() date(dt) 一個(gè)日期的值。
hour() hour(dt) 獲取小時(shí)。
minute() minute(dt) 獲取分鐘數(shù)。
second() second(dt) 獲取秒鐘數(shù)。
dayname() dayname(dt) 星期幾。
dayofmonth() dayofmonth(dt) 日期號(hào)。
monthname() monthname(dt) 月份名。
month() month(dt) 月份號(hào)。
monthname() monthname(dt) 月份名。
month() month(dt) 月份號(hào)。
year() year(dt) 年份。
curdate() curdate() 當(dāng)前日期。
curdate() curdate() 當(dāng)前日期。
curtime() curtime() 當(dāng)前時(shí)間。
now() now() 當(dāng)前date。
unix_timestamp() unix_timestamp(dt) UNIX時(shí)間戳。
utc_timestamp() utc_timestamp(dt) UTC時(shí)間戳。
posted on 2011-12-06 15:18 wayne woo 閱讀(396) 評(píng)論(0) 編輯 收藏 所屬分類: Database