oracle Day1

登录SCOTT用户(scott/tiger)
select*from emp;
–1.找出在(任何年份的)2月受聘的所有雇员
select * from emp where to_char(hiredate, ‘mm’) = 2;
–2.显示姓名字段以”A”开头的所有雇员的姓名
select ename from emp where ename like ‘A%’;
–3.列出所有办事员(“CLERK”)的姓名、编号和部门。
select ename, empno, deptno, job from emp where job = ‘CLERK’;
–4.找出佣金高于薪金60%的雇员
select * from emp where comm > nvl(sal, 0) * 0.6;
–5.部门中既不是经理(MANAGER)又不是办事员(CLERK)但其薪金大于或等于1500的所有雇员的详细资料
select *
from emp
where job != ‘MANAGER’
and job != ‘CLERK’
and sal >= 1500;
–6.找出收取佣金(COMM)的雇员的不同工作(distinct去重复)
select distinct job from emp where comm > 0;
–7.找出不收取佣金或收取的佣金低于100的雇员
select * from emp where nvl(comm, 0) < 100;
–8.找出各月第一天受雇的所有雇员
select * from emp where extract(day from to_date(hiredate)) = 1;
select*from emp where to_char(hiredate,’dd’)=1;
–9.找出早于35年之前受雇的雇员
select * from emp where months_between(sysdate, HIREDATE) > (12 * 35);
–10.列出薪金等于3000且在部门20工作的雇员的所有姓名和薪金
select ename, sal
from emp
where sal = 3000
and deptno = 20;
–11.显示所有雇员的姓名,并且用首字母大写显示
select initcap(ename) from emp;
–12.显示正好为5个字符的雇员的姓名
select ename from emp where length(ename) = 5;
–13.显示不带有”R”的雇员姓名
select ename from emp where ename not like ‘%R%’;
–14.显示所有雇员的姓名的前三个字符
select substr(ename,1,3) from emp;
–15.显示所有雇员的姓名,用”a”替换所有的”A”
select replace(ename,’A’,’a’)from emp;
–16.列出按降序排序的所有雇员的年薪(年薪=(工资+佣金)*12)
select * from emp order by ((sal + nvl(comm,0)) * 12) desc;
select ename,sal,comm,(sal+nvl(comm,0)) totmon from emp order by totmon desc;
–17.显示雇员姓名,根据其入职日期,将最老的雇员排在最前面。
select ename, hiredate from emp order by to_char(hiredate, ‘yyyy’) desc;
–18.显示所有雇员的姓名和加入公司的年数和月数(即工作了几年零几个月),并按年数及月数大的排在前面
select ename,
round(months_between(sysdate, hiredate) / 12) year,
mod(round(months_between(sysdate, hiredate)), 12) month
from emp
order by year desc;
–19.显示在一个月为30天的情况下所有雇员的日薪金,忽略余数
select empno,ename,hiredate,sal, floor(sal/30) daysal from emp;
–20.将显示所有雇员的入职日期拆分成年,月,日三个字段显示
select empno,ename,to_char(hiredate,’yyyy’) year,to_char(hiredate,’mm’) month,to_char(hiredate,’dd’) day from emp;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值