一、字符串函数
1、CONCAT(”字符串”,字段,……..):把传入的参数连接成一个字符串,返回连接后的字符串concat(‘adf’,'bb’) 返回adfbb
2、INSER(str,x,y,insert):将字符串str,x位置开始y个字符串长度替换为字符串insert;
3、LOWER(str) UPPER(str):将字符串转成大写或小写。
4、LEFT(str,x) RIGHT(str,x):分别返回最左边的x个字符和最右边的x个字符,如果第二个参数为null则返回null
5、LPAD(str,n,pad) RPAD(str,n,pad):用字符串pad对str最左边和最右边进行填充,直到长度为n个字符
6、TRIM(str) LTRIM(str) RTRIM(str)//去掉字符串两边、左边、和右边的空格
7、replace(str,a,b):用字符串b替换str中所有出现的字符串a的
8、strcmp(s1,s2):比较ASC大小,如果s1比s2小返回-1,如果s1比s2大返回1,如果s1等于s2返回0
9、substring(str,x,y):返回字符串str中的第x位置起y个字符串长度的字符串。
二、数值函数
1,ABS(x):返回x的绝对值
2,ceil(x):返回大于x的最小整数 2.1 2.5 2.9 返回 3 进1取中法
3,floor(x);返回小于x的最大整数 2.1 2.5 2.9 返回 2 割舍法
4,mod(x,y):返回x/y的模
5,rand():0-1之间的随机数
6,round(x,y):返回参数x的四舍五入的有y位小数的值
7,truncate(x,y):返回数字x截断为y位小数的结果truncate(1.239,2) 返回1.23
三、
日期函数
1,curdate():返回日期
2,now():返回日期时间
3,curtime():返回时间
4,unix_timestamp(now());返回unix时间戳
5,from_unixtime(1231314);返回时间戳的时间
6,week(now());
7,year(now());
8,hour(curtime());
9,minute(curtime());
10,monthname(now());月名
11,date_format(now(),”%Y-%m-%d %H:%i:%”)
四、
流程控制函数
1,if(value ,t,f); select if(字段>300,’v1′,’v2′) from ;如果条件成立返回v1,否则返回v2
2,ifnull(value1,value2)如果value1不为空返回value1,为空返回value;
3,case when[value1] then[result]………..else[default]end
case when then else end //select case when salary<=3000 then ’low’ else ’heigh’ end from …;
五、其他函数
1,database()当前
数据库
2,erdion()当前版本
3,user()当前用户
4,inet_aton(192.168.1.1);返回ip网络地址序
5,inet_ntoa(3232235777);根据网络地址序返回ip
6,md5();返回
加密后字符串