字符函数
length
例:查询'ABC张三'字节的长度
select length('ABC张三');
concat
例:将员工名字前面增加hello组成一个新列
select concat('hello',',',last_name) 新列 from employees;
upper
例:将abc改成大写
select upper('abc');
lower
例:将ABC改成小写
select lower('ABC');
instr
例:select imstr('我是一个好人','是');
substr
例:
select substr('郭襄爱上了杨过',6);
select substr('郭襄爱上了杨过',1,2);
lpad左填充
例:select lpad('我是个好人',7,'*');
rpad右填充
例:select rpad('我是个好人',7,'*');
trim
例:select trim(' 我 是 ');
数字函数
ceil
select ceil(-1.1);
floor
select floor(-1.1);
round
select round(-1.56);
rand
select rand();
truncate
select truncate(1.999,2);
日期函数
now
select now();
curdate
select curdate();
curtime
select curtime();
获取日期指定部分
select year(now());
select month(now());
select monthname(now());
datediff
select datediff('日期1','日期2');
流程控制函数
if函数
select if(判断式,'值1','值2');
case语句
case
when 条件1 then 显示的值1
when 条件2 then 显示的值2
...
else 显示的值n
end