sql 字符串函数、数学函数
-- 字符函数:
-- 查询结果姓名小写
select lower(ename), sal, job from emp;
-- 查询结果姓名大写
select upper(ename), sal, job from emp;
-- 名字5个字符
select ename, sal, job from emp where length(ename)=5;
-- 名字前3个字符
select substr(ename, 1,3), sal, job from emp; -- 从第1个开始
select substr(ename, 2,3), sal, job from emp; -- 3-->取3个
-- 名字首字母大写
select upper(substr(ename, 1,1)) || lower(substr(ename, 2, length(ename)-1)) from emp;
select concat(upper(substr(ename, 1,1)), lower(substr(ename, 2, length(ename)-1))) from emp; -- mysql 要使用concat()函数
-- 名字首字母小写
select lower(substr(ename, 1,1)) || upper(substr(ename, 2, length(ename)-1)) from emp;
select concat(lower(substr(ename, 1,1)), upper(substr(ename, 2, length(ename)-1))) from emp; -- mysql 要使用concat()函数
-- 名字里的A替换为a
select replace(ename, 'A', 'a') ename from emp;
-- 数学函数:(这一部分 mysql 要把 nvl 替换为ifnull)
select ename, job, nvl(sal, 0)+ nvl(comm, 0) sal, dname from emp, dept where emp.deptno = dept.deptno and ename = 'SMITH';
select ename, job, nvl(sal, 0)+ nvl(comm, 0) sal, dname from emp join dept on emp.deptno = dept.deptno where ename = 'SMITH';
-- 一个月30天,日薪是多少
select ename, round(nvl(sal, 0)/30) from emp; -- 精确到整数
select ename, round(nvl(sal, 0)/30, 2) from emp; -- 精确到小数点后两位
select ename, round(nvl(sal, 0)/30, -1) from emp;-- 精确到十位