MySQL存儲(chǔ)過程基本函數(shù)
[@more@]一.字符串類
CHARSET(str) //返回字串字符集
CONCAT (string2 [,... ]) //連接字串
INSTR (string ,substring ) //返回substring首次在string中出現(xiàn)的位置,不存在返回0
LCASE (string2 ) //轉(zhuǎn)換成小寫
LEFT (string2 ,length ) //從string2中的左邊起取length個(gè)字符
LENGTH (string ) //string長(zhǎng)度
LOAD_FILE (file_name ) //從文件讀取內(nèi)容
LOCATE (substring , string [,start_position ] ) 同INSTR,但可指定開始位置
LPAD (string2 ,length ,pad ) //重復(fù)用pad加在string開頭,直到字串長(zhǎng)度為length
LTRIM (string2 ) //去除前端空格
REPEAT (string2 ,count ) //重復(fù)count次
REPLACE (str ,search_str ,replace_str ) //在str中用replace_str替換search_str
RPAD (string2 ,length ,pad) //在str后用pad補(bǔ)充,直到長(zhǎng)度為length
RTRIM (string2 ) //去除后端空格
STRCMP (string1 ,string2 ) //逐字符比較兩字串大小,
SUBSTRING (str , position [,length ]) //從str的position開始,取length個(gè)字符,
注:mysql中處理字符串時(shí),默認(rèn)第一個(gè)字符下標(biāo)為1,即參數(shù)position必須大于等于1
mysql> select substring('abcd',0,2);
+-----------------------+
| substring('abcd',0,2) |
+-----------------------+
| |
+-----------------------+
1 row in set (0.00 sec)
mysql> select substring('abcd',1,2);
+-----------------------+
| substring('abcd',1,2) |
+-----------------------+
| ab |
+-----------------------+
1 row in set (0.02 sec)
TRIM([[BOTH|LEADING|TRAILING] [padding] FROM]string2) //去除指定位置的指定字符
UCASE (string2 ) //轉(zhuǎn)換成大寫
RIGHT(string2,length) //取string2最后length個(gè)字符
SPACE(count) //生成count個(gè)空格
二.數(shù)學(xué)類
ABS (number2 ) //絕對(duì)值
BIN (decimal_number ) //十進(jìn)制轉(zhuǎn)二進(jìn)制
CEILING (number2 ) //向上取整
CONV(number2,from_base,to_base) //進(jìn)制轉(zhuǎn)換
FLOOR (number2 ) //向下取整
FORMAT (number,decimal_places ) //保留小數(shù)位數(shù)
HEX (DecimalNumber ) //轉(zhuǎn)十六進(jìn)制
注:HEX()中可傳入字符串,則返回其ASC-11碼,如HEX('DEF')返回4142143
也可以傳入十進(jìn)制整數(shù),返回其十六進(jìn)制編碼,如HEX(25)返回19
LEAST (number , number2 [,..]) //求最小值
MOD (numerator ,denominator ) //求余
POWER (number ,power ) //求指數(shù)
RAND([seed]) //隨機(jī)數(shù)
ROUND (number [,decimals ]) //四舍五入,decimals為小數(shù)位數(shù)]
注:返回類型并非均為整數(shù),如:
(1)默認(rèn)變?yōu)檎沃?br />mysql> select round(1.23);
+-------------+
| round(1.23) |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
mysql> select round(1.56);
+-------------+
| round(1.56) |
+-------------+
| 2 |
+-------------+
1 row in set (0.00 sec)
(2)可以設(shè)定小數(shù)位數(shù),返回浮點(diǎn)型數(shù)據(jù)
mysql> select round(1.567,2);
+----------------+
| round(1.567,2) |
+----------------+
| 1.57 |
+----------------+
1 row in set (0.00 sec)
SIGN (number2 ) //返回符號(hào),正負(fù)或0
SQRT(number2) //開平方
三.日期時(shí)間類
ADDTIME (date2 ,time_interval ) //將time_interval加到date2
CONVERT_TZ (datetime2 ,fromTZ ,toTZ ) //轉(zhuǎn)換時(shí)區(qū)
CURRENT_DATE ( ) //當(dāng)前日期
CURRENT_TIME ( ) //當(dāng)前時(shí)間
CURRENT_TIMESTAMP ( ) //當(dāng)前時(shí)間戳
DATE (datetime ) //返回datetime的日期部分
DATE_ADD (date2 , INTERVAL d_value d_type ) //在date2中加上日期或時(shí)間
DATE_FORMAT (datetime ,FormatCodes ) //使用formatcodes格式顯示datetime
DATE_SUB (date2 , INTERVAL d_value d_type ) //在date2上減去一個(gè)時(shí)間
DATEDIFF (date1 ,date2 ) //兩個(gè)日期差
DAY (date ) //返回日期的天
DAYNAME (date ) //英文星期
DAYOFWEEK (date ) //星期(1-7) ,1為星期天
DAYOFYEAR (date ) //一年中的第幾天
EXTRACT (interval_name FROM date ) //從date中提取日期的指定部分
MAKEDATE (year ,day ) //給出年及年中的第幾天,生成日期串
MAKETIME (hour ,minute ,second ) //生成時(shí)間串
MONTHNAME (date ) //英文月份名
NOW ( ) //當(dāng)前時(shí)間
SEC_TO_TIME (seconds ) //秒數(shù)轉(zhuǎn)成時(shí)間
STR_TO_DATE (string ,format ) //字串轉(zhuǎn)成時(shí)間,以format格式顯示
TIMEDIFF (datetime1 ,datetime2 ) //兩個(gè)時(shí)間差
TIME_TO_SEC (time ) //時(shí)間轉(zhuǎn)秒數(shù)]
WEEK (date_time [,start_of_week ]) //第幾周
YEAR (datetime ) //年份
DAYOFMONTH(datetime) //月的第幾天
HOUR(datetime) //小時(shí)
LAST_DAY(date) //date的月的最后日期
MICROSECOND(datetime) //微秒
MONTH(datetime) //月
MINUTE(datetime) //分
附:可用在INTERVAL中的類型
DAY ,DAY_HOUR ,DAY_MINUTE ,DAY_SECOND ,HOUR ,HOUR_MINUTE ,HOUR_SECOND ,MINUTE ,MINUTE_SECOND,MONTH ,SECOND ,YEAR
當(dāng)前題目:mysql存儲(chǔ)過程基本函數(shù)(轉(zhuǎn))
網(wǎng)站網(wǎng)址:http://jinyejixie.com/article38/jopgpp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、動(dòng)態(tài)網(wǎng)站、定制網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站改版、網(wǎng)頁(yè)設(shè)計(jì)公司
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源:
創(chuàng)新互聯(lián)