bitscn.com
mysql存储过程的基本函数
(1).字符串类charset(str) //返回字串字符集concat (string2 [,... ]) //连接字串instr (string ,substring ) //返回substring首次在string中出现的位置,不存在返回0lcase (string2 ) //转换成小写left (string2 ,length ) //从string2中的左边起取length个字符length (string ) //string长度load_file (file_name ) //从文件读取内容locate (substring , string [,start_position ] ) 同instr,但可指定开始位置lpad (string2 ,length ,pad ) //重复用pad加在string开头,直到字串长度为lengthltrim (string2 ) //去除前端空格repeat (string2 ,count ) //重复count次replace (str ,search_str ,replace_str ) //在str中用replace_str替换search_strrpad (string2 ,length ,pad) //在str后用pad补充,直到长度为lengthrtrim (string2 ) //去除后端空格strcmp (string1 ,string2 ) //逐字符比较两字串大小,substring (str , position [,length ]) //从str的position开始,取length个字符,注:mysql中处理字符串时,默认第一个字符下标为1,即参数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 ) //转换成大写right(string2,length) //取string2最后length个字符space(count) //生成count个空格(2).数学类abs (number2 ) //绝对值bin (decimal_number ) //十进制转二进制ceiling (number2 ) //向上取整conv(number2,from_base,to_base) //进制转换floor (number2 ) //向下取整format (number,decimal_places ) //保留小数位数hex (decimalnumber ) //转十六进制注:hex()中可传入字符串,则返回其asc-11码,如hex('def')返回4142143也可以传入十进制整数,返回其十六进制编码,如hex(25)返回19least (number , number2 [,..]) //求最小值mod (numerator ,denominator ) //求余power (number ,power ) //求指数rand([seed]) //随机数round (number [,decimals ]) //四舍五入,decimals为小数位数]注:返回类型并非均为整数,如:(1)默认变为整形值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)可以设定小数位数,返回浮点型数据mysql> select round(1.567,2); +----------------+ | round(1.567,2) | +----------------+ | 1.57 | +----------------+ 1 row in set (0.00 sec) sign (number2 ) //(3).日期时间类addtime (date2 ,time_interval ) //将time_interval加到date2convert_tz (datetime2 ,fromtz ,totz ) //转换时区current_date ( ) //当前日期current_time ( ) //当前时间current_timestamp ( ) //当前时间戳date (datetime ) //返回datetime的日期部分date_add (date2 , interval d_value d_type ) //在date2中加上日期或时间date_format (datetime ,formatcodes ) //使用formatcodes格式显示datetimedate_sub (date2 , interval d_value d_type ) //在date2上减去一个时间datediff (date1 ,date2 ) //两个日期差day (date ) //返回日期的天dayname (date ) //英文星期dayofweek (date ) //星期(1-7) ,1为星期天dayofyear (date ) //一年中的第几天extract (interval_name from date ) //从date中提取日期的指定部分makedate (year ,day ) //给出年及年中的第几天,生成日期串maketime (hour ,minute ,second ) //生成时间串monthname (date ) //英文月份名now ( ) //当前时间sec_to_time (seconds ) //秒数转成时间str_to_date (string ,format ) //字串转成时间,以format格式显示timediff (datetime1 ,datetime2 ) //两个时间差time_to_sec (time ) //时间转秒数]week (date_time [,start_of_week ]) //第几周year (datetime ) //年份dayofmonth(datetime) //月的第几天hour(datetime) //小时last_day(date) //date的月的最后日期microsecond(datetime) //微秒month(datetime) //月minute(datetime) //分返回符号,正负或0sqrt(number2) //开平方
bitscn.com