Oracle基础——单行函数练习(二)
练习基于Oracle数据库中HR用户下的employess表
- 查询系统当前日期
select sysdate from dual;
- 请查询每个员工的名字、薪水和加薪15.5%之后的薪水(trunc取整)
Select last_name,salary,trunc(salary*1.155) "new salary" from employees;
- 显示员工加薪15.5%(取整)之后员工的名字、原薪水和增加的薪水。(不允许做update操作,trunc取整)
Select last_name,salary,trunc(salary*0.155) "new salary" from employees;
- 请显示所有以'J','A','M'打头的员工的名字和名字长度,且按照名字排升序
select last_name,LENGTH(last_name)
from employees
where substr(last_name,0,1) in ('J','A','M') order by last_name asc;
- 请查询员工名和工作时间(换算成月并取整),并按工作时间排降序
Select last_name,trunc(months_between(sysdate,hire_date),0) from employees order by trunc(months_between(sysdate,hire_date),0) desc;
- 请查询员工的名字和薪水,并将薪水列变成15个字符长度,左边填充“$”符号
select last_name,lpad(salary,15,'$') from employees;
- 请查询部门id为90的所有员工的名字和他们参加工作的星期数(保留2位小数,不需要四舍五入)使用
select last_name , trunc((sysdate-hire_date)/7,2) from employees where department_id=90
- 创建报告,显示员工名和奖金系数,如果奖金系数为空,则显示$无奖金
select last_name,decode(commission_pct,'','无奖金',commission_pct) from employees;
- 请使用case语句,查询员工的job_id和级别.例如:
job_id |
Grade |
AD_PRES |
A |
ST_MAN |
B |
IT_PROG |
C |
SA_REP |
D |
ST_CLERK |
E |
Others |
0 |
select t.job_id, decode(t.job_id,
'AD_PRES',
'A','ST_MAN',
'B','IT_PROG',
'C','SA_REP',
'D','ST_CLERK',
'E','0')
from employees t;
- 请使用decode语句,查询员工的job_id和级别.例如:
job_id |
Grade |
AD_PRES |
A |
ST_MAN |
B |
IT_PROG |
C |
SA_REP |
D |
ST_CLERK |
E |
Others |
0 |
Select job_id,
case job_id
when 'AD_PRES' then 'A'
when 'ST_MAN' then 'B'
when 'IT_PROG' then 'C'
when 'SA_REP' then 'D'
when 'ST_CLERK' then 'E'
else '0'
end "Grage"
from employees;