16. mysql常用函数-字符串函数-数字函数-日期函数-高级函数
函数
描述
实例
char_length(s)
返回字符串 s 的字符数
select char_length('lijw') as '长度';
concat(s1,s2...sn)
字符串 s1,s2 等多个字符串合并为一个字符串
select concat('happy','niu','year');
lower(s)
将字符串 s 的所有字母变成小写字母
select lower('happy niu year');
upper(s)
将字符串转换为大写
select upper("happy niu year");
substr(s, start,length)
从字符串 s 的 start 位置截取长度为 length 的子字符串
select substr("happy niu year",1,2);
trim(s)
去掉字符串 s 开始和结尾处的空格
select trim(' happy niu year ')
示例:
rand()
返回 0 到 1 的随机数
select rand();
round(小 小数 数, 保留 几位 位)
四舍五入保留几位小数
select round(3.1415926,2) ;
least(expr1, expr2, expr3, ...)
返回列表中的最小值
select least(13, 14, 521, 74, 1)
greatest(expr1, expr2,expr3, ...)
返回列表中的最大值
select greatest(13, 14, 521, 74, 1)
函数名
now() 和 sysdate()
返回系统的当前日期和时间
select now(); 或 select sysdate();
curdate()
返回当前日期
select curdate();
curtime()
返回当前系统时间
select curtime();
year(d)
返回d的中的年份
select year(now());
month(d)
返回d的中的月份
select month(now());
day(d)
返回d中的日
select day(now());
current_user()
返回当前用户
select current_user();
ifnull(v1,v2)
如果 v1 的值不为 null,则返回 v1,否则返回 v2。
select ifnull(null,'hello word')
isnull(expression)
判断表达式是否为 null
select isnull(null);