--1 以首字母大写的方式显示所有员工的姓名
select *from emp;
select substr(upper(ename),0,1) from emp;
select substr(lower(ename),2)from emp;
select substr(upper(ename),0,1)||substr(lower(ename),2)from emp;
--2.将员工的职位用小写显示
select emp.ename as 员工 ,lower(job) as 职位 from emp;
--3 将员工的名字分别用大写和小写显示
select upper(ename) as 名字大写,lower(ename) as 名字小写 from emp;
--4 将员工名字,首字母小写,其他字母大写的方式显示
select substr(lower(ename),0,1)||substr(upper(ename),2)from emp;
--5 显示员工姓名为5 个字符的员工
select * from emp where ename like '_____';
select * from emp where length(ename)=5;
--6.显示所有员工姓名的前三个字符
select substr(ename,0,3) from emp;
--7.显示所有员工姓名的后三个字符
select substr(ename,length(ename)-2) from emp ;
--8.显示所有员工的姓名,用a 替换所有"A"
select replace(ename,'A','a') from emp;
--9.查询一个月前入职的员工
select * from emp where substr(to_char(hiredate,'yyyy-MM-dd'),6,2)=(substr(to_char(sysdate,'yyyy-MM-dd'),6,2)-1);
select * from emp where to_char(hiredate,'MM')=(to_char(sysdate,'MM')-1);
--10 显示在一个月固定为30 天的情况所有员工的日薪,忽略余数
select ename as 员工, sal as 月薪,round(sal/30,2) as 日薪 from emp;
--11 显示所有12 月份入职的员工
select * from emp where substr(to_char(hiredate,'yyyy-MM-dd'),6,2)='12';
select * from emp where to_char(hiredate,'MM')='12';
--12 显示员工的年薪(12 个月的工资+补贴,补贴是每个月都有)
select e.*,to_char((sal+nvl(comm,0))*12,'L999,999,999') as 年薪 from emp e;
--13 显示所有员工的姓名、加入公司的年份和月份,并且按照年份排序
select ename as 姓名, substr(to_char(hiredate,'yyyy-MM-dd'),0,4)as 年份,substr(to_char(hiredate,'yyyy-MM-dd'),6,2)as 月份
from emp order by 年份;
select ename as 姓名, to_char(hiredate,'yyyy')as 年份,to_char(hiredate,'MM')as 月份
from emp order by 年份;