MySQL函式列表

2021-08-03 17:13:28 字數 1603 閱讀 6575

mysql中,提供了豐富的函式,簡化了使用者對資料的操作

包括數學函式、字串函式、日期和時間函式、條件判斷函式、加密函式等

abs(x),返回x的絕對值

sqrt(x),返回x的非負2次方根

mod(x,y),返回x被y除后的餘數

ceiling(x),返回不小於x的最小整數

floor(x),返回不大於x的最大整數

round(x,y),對x進行四捨五入操作,小數點後保留y位

truncate(x,y),捨去x中小數點y位後面的數

sing(x),返回x的符號,-1、0或者1

length(str),返回字串str的長度

concat(s1,s2,……),返回乙個或者多個字串連線,產生的新的字串

trim(str),刪除字串兩側的空格

replace(str,s1,s2),使用字串s2,替換字串str中所有的字串s1

substring(str,n,len),返回字串str的子串,起始位置為n,長度為len

reverse(str),返回字串反轉後的結果

locate(s1,str),返回子串s1在字串str中的起始位置

curdate()——獲取系統當前日期

curtime()——獲取系統當前時間

sysdate()——獲取當前系統日期和時間

time_to_sec()——返回將時間轉換成秒的結果

adddate()——執行日期的加運算

sbudate()——執行日期的減運算

date_format()——格式化輸入日期和時間值

if(expr,v1,v2)——如果expr表示式,為true返回v1,否則返回v2

ifnull(v1,v2)——如果v1不為null,返回v1,否則返回v2

case expr when v1 then r1[when v2 then r2……][else m] end——如果,expr值等於v1,v2等,則返回對應位置then後面的結果,否則,返回else後的結果rn

md(str)——對字串str,進行md5加密

encode(str,pwd_str)——使用pwd作為密碼,加密字串str

decode(str,pwd_str)——使用pwd作為密碼,解碼字串str

查詢student表中所有記錄,將各個欄位的值使用下劃線連線起來

可以看到,使用concat函式,將student表中各個欄位的值,使用下劃線連線起來了。

注意,concat(str1,str2,……)返回的結果為,連線引數產生的字串,如果,有任何乙個引數為null,則返回的值為null

查詢student表中,id和gender字段值,如果gender欄位的值為na,則返回1,如果不為na,則返回0

可以看出,gender字段值為na的記錄,都返回了1,gender字段值為nv或者null的記錄,都返回了0

Mysql常用函式列表

字串類 charset str 返回字串字符集 concat string2 連線字串 instr string substring 返回substring首次在string中出現的位置,不存在返回0 lcase string2 轉換成小寫 left string2 length 從string2中...

Mysql常用函式列表

字串類 charset str 返回字串字符集 concat string2 連線字串 instr string substring 返回substring首次在string中出現的位置,不存在返回0 lcase string2 轉換成小寫 left string2 length 從string2中...

Mysql常用函式列表

字串類 charset str 返回字串字符集 concat string2 連線字串 instr string substring 返回substring首次在string中出現的位置,不存在返回0 lcase string2 轉換成小寫 left string2 length 從string2中...