本篇介紹MySQ函數的一些常用函數。
IF(expr,v1,v2) expr表達式為true時傳回v1,否則回傳v2

IFNULL(v1,v2) 如果v1為NULL,回傳v2 ;v1不為NULL 則回傳v1

CASE expr WHEN v1 THEN r1 [WHEN v2 THEN r2][......] [ELSE m ] END
如果expr 等於v1.v2..中的值則回傳THEN後面的r1,r2.. 否則傳回ELSE後面的值m

CASE WHEN v1 THEN r1 [WHEN v2 THEN r2][......] [ELSE m] END
當v1,v2...中某個值為true時回傳THEN之後的值,否則傳回ELSE之後的值

VERSION() 傳回MySql的版本

##CONNECTION_ID() 回傳Mysql目前的連線次數

SHOW PROCESSLIST; SHOW FULL PROCESSLIST; 顯示執行的執行緒

DATEBASE(),SCHEMA( ) 傳回目前的資料庫

USER()、CURRENT_USER()、SYSTEM_USER()、SESSION_USER() 傳回目前的使用者名稱

CHARSET(str) 傳回str的字元集

#COLLATION(str) 傳回str的字元排列方式

LAST_INSERT_ID() 傳回AUTO_INCREMENT最後產生的id值,如果為批量插入數據,則傳回批量中的第一個

c--MD5(str ) 回傳str MD5加密 32位元十六進位

加密 ENCODE(str,pwd_str) 使用pwd_str作為密碼加密str,與str字串長度相同的二進位字串

解密 DECODE('str',pwd_str) 將pwd_str 當作密碼解密str,與上面的ENCODE()互為反函數
#FORMAT(x,n) 將數字x格式化,保留n為小數四捨五入後以字串形式傳回

CONV(N,from_base,to_base)將N由from_base進位轉換為to_base進位

#BENCHMARK(count,expr) 重複執行expr總共count次數

#CONVERT(str USING charset) 將str轉換為對應的charset
##CAST(x AS type),CONVERT(x,type) 回傳將x轉為type類型的值
#
以上是分享關於MySQ函數的實例介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!