Oracle第二章习题及答案.doc





《Oracle第二章习题及答案.doc》由会员分享,可在线阅读,更多相关《Oracle第二章习题及答案.doc(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-作者xxxx-日期xxxxOracle第二章习题及答案【精品文档】一、基于自己创建表的操作1:创建一张学生表student,拥有stuid,stuname,sex,三个字段,其中stuid为主键。create table student( stuid int primary key, stuname VARCHAR(20), sex VARCHAR(20)2:为该表增加一个新列score。alter table student add(score varchar(10);3:修改该表score列名为stuscore。alter table student rename column scor
2、e to stuscoree;4:为student表插入5条记录。insert into student values(1,张三丰,男,80);insert into student values(2,阿悄,女,70);insert into student values(3,陈龙,男,90);insert into student values(4,章子怡,女,50);insert into student values(5,张卫健,男,60);5:查询student表中的全部数据,其中列名为中文。select STUID as 学号,STUNAME as 姓名 ,SEX as 性别,STU
3、SCOREE as 分数 from student;6:查询学生姓名和分数,并是查询结果按照学生成绩降序排列。select STUNAME,STUSCOREE from student order by STUSCOREE desc;7:修改所有性别为“男”的学生信息为性别为“male”。update student set SEX=male where SEX=男;8:删除所有记录。delete from student;9:删除student表。drop table student;二、基于emp表的操作1:创建一张新表emp1,和emp表结构和记录完全一样。 create table e
4、mp1 as select*from Scott.Emp;基于emp1表的操作:1:选择部门30中的雇员。select*from emp1 where DEPTNO=30 and JOB=CLERK;2:列出所有办事员(CLERK)的姓名、编号和部门。select ENAME,EMPNO,DEPTNO from emp1 where JOB=CLERK;3:找出佣金高(comm)于薪金的雇员。 select*from emp1 where COMM SAL and JOB=CLERK;4:找出佣金高于薪金60%的雇员。select*from emp1 where COMM*0.6 SAL an
5、d JOB=CLERK;5:找出部门10中所有经理和部门20中所有办事员的详细资料。select*from emp1 where DEPTNO=10 and JOB=MANAGER union select*from emp1 where JOB=SALESMAN;6:找出部门10中所有经理和部门20中所有办事员以及既不是经理又不是办事员但其薪金大于或等于2000的所有雇员的详细资料。select*from emp1 where DEPTNO=10 and JOB=MANAGER union select*from emp1 where JOB=SALESMAN union select*fr
6、om emp1 where JOB in(CLERK) and SAL=2000;7:找出收取佣金的雇员的不同工作。 select distinct JOB from emp1 where job=CLERK;8:找出不收取佣金或收取佣金低于100的雇员。select *from emp1 where COMM is null or nvl(COMM,0)12;3:显示只有首字母大写的所有雇员的姓名 select UPPER( SUBSTR(ename,1,1) |LOWER(SUBSTR(ename,2,LENGTH(ename)-1) FROM emp where JOB=CLERK;4:
7、显示正好为15个字符的雇员姓名select deptno,ename from emp where length(ename)=15 and JOB=CLERK;5:显示不带有R的雇员姓名 select ename from emp where ename not like %R%and JOB=CLERK;6:显示所有雇员的姓名的前3个字符select substr(ename,1,3) from emp where JOB=CLERK;7:显示所有雇员的姓名,用a替换所有的Aselect replace(ename,A,a) from emp;8:显示所有雇员的姓名以及满10年服务年限的日
8、期select ename,hiredate,add_months(hiredate,10*12) from emp;9:显示雇员的详细资料,按姓名排序select * from emp order by ename;10:显示雇员姓名,根据其服务年限,将最老的雇员排在最前面select empno,ename,job,mgr,hiredate,sal ,comm,deptno ,(sysdate-hiredate)/365 from emp order by (sysdate-hiredate)/365 desc;11:显示所有雇员的姓名、工作和薪金,按工作内的工作的降序顺序排序,而工作按薪
9、金排序select ename,job,sal from emp order by job desc,sal asc;12:显示所有雇员的姓名和加入公司的年份和月份,按雇员受雇日所在月排序,并将最早年份的项目排在最前面select ename,to_char(hiredate,YYYY) year1,to_char(hiredate,MON) month1 from emp order by year1 asc,month1;13:显示在一个月为30天的情况下所有雇员的日薪金,忽略小数select round(sal/30,0) as daypay from emp;14:找出在(任何年份的)
10、2月份受雇的所有雇员select * from emp where hiredate like %-2月%;15:对于每个雇员,显示其加入公司的天数 select round(sysdate-hiredate) from emp;16:显示姓名字段的任何位置,包含A的所有雇员的姓名select ename from emp where ename like %A%;17:以年、月和日显示所有雇员的服务年限select ename,to_number(to_char(sysdate,YYYY)-to_number(to_char(hiredate,YYYY)-1,to_number(to_cha
11、r(sysdate,mm)-to_number(to_char(hiredate,mm) +10,to_number(to_char(sysdate,dd)-to_number(to_char(hiredate,dd)+30 from emp;18: 列出至少有一个雇员的所有部门 select deptno from emp group by deptno having count(deptno)0;19:列出薪金比“SMITH”多的所有雇员SELECT ename,sal, deptno FROM emp WHERE sal(SELECT sal FROM emp WHERE ename=S
12、MITH);20:列出所有雇员的姓名及其部门名select ENAME,DEPTNO from emp where JOB=CLERK; 21:列出所有入职日期早于其直接上级的所有雇员SELECT e.ename as 职工, m.ename as 经理 FROM emp e left join emp m on (e.mgr=m.empno) where e.hiredate1500;23:列出薪金高于公司平均水平的所有雇员select ename, deptno from emp where sal(select avg(sal) from emp);24:列出与“SCOTT”从事相同工作
13、的所有雇员 select deptno,ename from emp where job=(select job from emp where ename=SCOTT);25:列出薪金高于在部门30工作的所有雇员的薪金SELECT ename,sal from emp where sal all(select sal from emp where deptno=30);26:列出薪金高于在部门30工作的最高的薪金SELECT ename,sal from emp where salall(select max(sal) from emp where deptno=30);27:列出每个部门雇员
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Oracle 第二 习题 答案

限制150内