学号姓名Oracle练习题
- 格式:doc
- 大小:48.50 KB
- 文档页数:5
三、综合题(共48分)《软13级A》Oracle数据库有以下有相互关联的3个表:Student (学号, 姓名, 性别, 出生日期, 专业);Course(课程号, 课程名,学分);Score (学号, 课程号, 成绩)1、写出下列SQL语句。
(共24分)(1) 给“软件工程”专业选修了“c100”号课程的学生成绩加10分。
(2) 列出所有没有学生选修的课程号和课程名称。
(3) 显示score表中成绩为70,80或90的学号、姓名、课程号。
(4)查询所有成绩高于平均成绩的学号、课程号和成绩(5)显示student表中“软件工程”专业或性别为“女”的同学所有记录。
(6)查询Score表中成绩最高的前5条记录。
2、编写存储过程TotalScore,要求计算出score表中“c105”号课程的最高分和平均分,然后将最高分和平均分显示出来。
(8分)3、创建函数xkrs,要求输入课程编号作为参数,函数返回相应课程的选课人数。
(8分)4、在score表上创建触发器,当删除记录的时候,若课程成绩低于60则不能删除该选课记录。
(8分)1、(每小题4分,共24分)(1) 给“软件工程”专业选修了“c100”号课程的学生成绩加10分。
Upate score set 成绩=成绩+10 where 课程号=‘c105‘and 学号in(select 学号from student where 专业=‘软件工程’)(2) 列出所有没有学生选修的课程号和课程名称。
Select 课程号,课程名from coursewhere课程号not in (select distinct 课程号from score)(3) 显示score表中成绩为70,80或90的学号、姓名、课程号。
Select score.学号,姓名,课程号from score,studentWhere score.学号=student.学号and 成绩in(70,80,90)(4)查询所有成绩高于平均成绩的学号、课程号和成绩Select 学号,课程号,成绩from scoreWhere 成绩>(select avg(成绩) from score )(5)显示student表中“软件工程”专业或性别为“女”的同学所有记录。
Oracle练习题+习题答案(张表+题)create table student( sno varchar2(10) primary key,sname varchar2(20),sage number(2),ssex varchar2(5));create table teacher(tno varchar2(10) primary key,tname varchar2(20));create table course(cno varchar2(10),cname varchar2(20),tno varchar2(20),constraint pk_course primary key (cno,tno));create table sc(sno varchar2(10),cno varchar2(10),score number(4,2),constraint pk_sc primary key (sno,cno));/*******初始化学生表的数据******/insert into student values ('s001','张三',23,'男');insert into student values ('s002','李四',23,'男'); create table student(insert into student values ('s003','吴鹏',25,'男'); sno varchar2(10) primary key,insert into student values ('s004','琴沁',20,'女'); sname varchar2(20),insert into student values ('s005','王丽',20,'女'); sage number(2),insert into student values ('s006','李波',21,'男'); ssex varchar2(5)insert into student values ('s007','刘玉',21,'男'); );insert into student values ('s008','萧蓉',21,'女');insert into student values ('s009','陈萧晓',23,'女');insert into student values ('s010','陈美',22,'女');commit;/******************初始化教师表***********************/ insert into teacher values ('t001', '刘阳');create table teacher(insert into teacher values ('t002', '谌燕');tno varchar2(10) primary key,insert into teacher values ('t003', '胡明星');tname varchar2(20)commit; );/***************初始化课程表****************************/ insert into course values ('c001','J2SE','t002');insert into course values ('c002','Java Web','t002');insert into course values ('c003','SSH','t001'); create table course(insert into course values ('c004','Oracle','t001'); cnovarchar2(10),insert into course values ('c005','SQL SERVER 2005','t003'); cname varchar2(20),insert into course values ('c006','C#','t003'); tno varchar2(20),insert into course values ('c007','JavaScript','t002');constraint pk_course primary key (cno,tno)insert into course values ('c008','DIV+CSS','t001'); );insert into course values ('c009','PHP','t003');insert into course values ('c010','EJB3.0','t002');commit;/***************初始化成绩表***********************/insert into sc values ('s001','c001',78.9);insert into sc values ('s002','c001',80.9);create table sc(insert into sc values ('s003','c001',81.9);sno varchar2(10),insert into sc values ('s004','c001',60.9);cno varchar2(10),insert into sc values ('s001','c002',82.9);score number(4,2),insert into sc values ('s002','c002',72.9);constraint pk_sc primary key (sno,cno)insert into sc values ('s003','c002',81.9); ); insert into sc values ('s001','c003','59'); commit;练习:注意:以下练习中的数据是根据初始化到数据库中的数据来写的SQL 语句,请大家务必注意。
Oracle基础练习题及答案(多表查询1)(共5篇)第一篇:Oracle基础练习题及答案(多表查询1)利用scott用户自带的四张表完成如下作业:1.列出至少有一个员工的所有部门select b.deptno,b.dname from emp a,dept b where a.deptno=b.deptno group by b.deptno,b.dname having count(*)>=1;2.列出薪金比SMITH高的所有员工select * from emp where sal>(select sal from emp where ename='SMITH');3.列出所有员工的姓名及其直接上级领导的姓名select a.ename,b.ename “leader” from emp a,emp b wherea.mgr=b.empno;4.列出受雇日期早于其直接上级的所有员工的编号,姓名,部门名称select a.empno,a.ename,a.hiredate,c.dname from emp a,emp b,dept c where a.mgr=b.empno and a.deptno=c.deptno anda.hiredate5.列出部门名称和这些部门的员工信息,同时列出那些没有员工的部门select b.dname,a.* from emp a,dept b wherea.deptno(+)=b.deptno;6.列出所有CLERK(办事员)的姓名,及其部门名称,部门人数select aa.ename,aa.job,bb.dname,(select count(a.deptno)from emp a,dept b where a.deptno=b.deptno and b.dname=bb.dname group by a.deptno)from emp aa,dept bb where aa.deptno(+)=bb.deptno and aa.job='CLERK';7.列出最低薪金大于1500的各种工作及从事此工作的全部雇员人数select a.job,min(sal),count(ename)from emp a,dept b wherea.deptno=b.deptno having min(sal)>1500 group by a.job;8.列出在部门SALES(销售部)工作的员工的姓名,假定不知道销售部的部门编号。
oracle习题带答案(四)进入自己创建的用户下进行以下操作。
1、创建表STUDENT、COURSE、GRADE,各个表的结构如下:(1) STUDENT学号NUMBER(6),姓名V ARCHAR2(12)入学时间DA TE,专业V ARCHAR2(20),性别CHAR(2),年龄INTEGER(2) COURSE课程号NUMBER(6),课程名称V ARCHAR2(20),学时INTEGER,学分INTEGER(3) GRADE学号NUMBER(6),课程号NUMBER(6),成绩NUMBER(2)2、向上面的三个表中分别插入5条纪录。
答案如下:create table student(学号number(6),姓名varchar2(12),入学时间date,专业varchar2(20),性别char(2),年龄integer);create table course(课程号number(6),课程名称varchar2(20),学时integer,学分integer);create table grade(学号number(6),课程号number(6),成绩number);insert into student (学号,姓名,入学时间,专业,性别,年龄)values(100001,'dongji',to_date('2002-07-23','yyyy-mm-dd'), 'computer','男',23); insert into student (学号,姓名,入学时间,专业,性别,年龄)values(100002,'dongji2',to_date('2002-07-23','yyyy-mm-dd'), 'computer','女',23); insert into student (学号,姓名,入学时间,专业,性别,年龄)values(100003,'dongji3',to_date('2002-07-23','yyyy-mm-dd'), 'computer','男',23); insert into student (学号,姓名,入学时间,专业,性别,年龄)values(100004,'dongji4',to_date('2002-07-23','yyyy-mm-dd'), 'computer','男',23); insert into student (学号,姓名,入学时间,专业,性别,年龄)values(100005,'dongji5',to_date('2002-07-23','yyyy-mm-dd'), 'computer','男',23); insert into student (学号,姓名,入学时间,专业,性别,年龄)values(100006,'dongji6',to_date('2002-07-23','yyyy-mm-dd'), 'computer','男',23); insert into course (课程号,课程名称,学时,学分)values (000001, '计算机基础', 30, 3);insert into course (课程号,课程名称,学时,学分)values (000002, '软件工程', 20, 2);insert into course (课程号,课程名称,学时,学分)values (000003, '操作系统', 40, 2);insert into course (课程号,课程名称,学时,学分)values (000004, '组成原理', 40, 3);insert into course (课程号,课程名称,学时,学分)values (000005, 'c语言', 40, 3);insert into grade(学号,课程号,成绩)values(100001,000001, 90);insert into grade(学号, 课程号,成绩)values(100001,000002, 90);insert into grade(学号, 课程号,成绩)values(100002,000002, 90);insert into grade(学号, 课程号,成绩)values(100003,000001, 90);insert into grade(学号, 课程号,成绩)values(100004,000001, 90);。
Oracle 考试题一:单选题(每题1.5分,共60分)1.学生信息表StudentInfo如下所示:学号姓名所在省市0001 李辉北京0002 张明上海0003 王小玉北京0004 李淑华湖南0005 赵静上海┆┆┆查询所有学生来自于哪几个省市使用的语句为()。
(选择一项)A) Select unique 所在省市 from StudentInfoB) Select 所在省市 from StudentInfoC) Select only 所在省市 from StudentInfoD) Select distinct 所在省市 from StudentInfo2. 公司需要管理员工档案,你创建了2个表:员工表employees和部门表departments。
以下是两表的部分内容。
employees编号姓名年龄部门编号1 王涛 25 12 张力 24 13 李明 30 24 高嘉 24 3Departments编号部门名称1 人力资源部2 技术部3 销售部下列那列适合作为外键()。
(选择一项)A) Employees中的编号B) Employees中的部门编号C) departments中的编号D) 以上都适合3. 你使用以下T-SQL语句创建了一个视图v_emp和一个表students,create view v_emp as select * from emp where deptno=10;create table students(id number(5),stuname varchar2(10))请问这两个语句是:()。
(选择一项)A) DDL(数据定义语言)B) DML(数据操纵语言)C) DCL(数据控制语言)D) DQL (数据查询语言)4.当SQL登录帐户被授权为数据库用户后,要查询数据库中的表,还需要对其赋予select 权限,实现赋权的T-SQL语言属于()。
(选择一项)A) DDL(数据定义语言)B) DML(数据操纵语言)C) DCL(数据控制语言)D) DQL (数据查询语言)5. 你是公司的数据库管理员,数据库benet中有个员工表employees,该表中有职务列。
二、SQL语言(本大题共4小题,每空5分,总计40分)(1)请用系统用户登陆,创建用户zhang,口令为wang,并且赋予该用户创建表、视图、索引、序列、同义词、过程、函数的权限。
将代码和运行结果硬拷贝到下面:要求:修改sqlplus默认提示符为本人的姓名全称,方法举例如下:set sqlprompt liangyongxian>(2)创建上述学生表。
将代码和运行结果硬拷贝到下面:要求:修改sqlplus默认提示符为本人的姓名全称,方法举例如下:set sqlprompt liangyongxian>(3)向学生表插入两条数据。
将代码和运行结果硬拷贝到下面:要求:修改sqlplus默认提示符为本人的姓名全称,方法举例如下:set sqlprompt liangyongxian>(4)将第一个学生的年龄改为原来的年龄加1岁。
将代码和运行结果硬拷贝到下面:要求:修改sqlplus默认提示符为本人的姓名全称,方法举例如下:set sqlprompt liangyongxian>(5)将最后一条学生数据删除。
将代码和运行结果硬拷贝到下面:要求:修改sqlplus默认提示符为本人的姓名全称,方法举例如下:set sqlprompt liangyongxian>(6)查询所有学生的详细信息。
将代码和运行结果硬拷贝到下面:要求:修改sqlplus默认提示符为本人的姓名全称,方法举例如下:set sqlprompt liangyongxian>(7)查询年龄为某个区间的学生信息。
将代码和运行结果硬拷贝到下面:要求:修改sqlplus默认提示符为本人的姓名全称,方法举例如下:set sqlprompt liangyongxian>(8)查询和学号为‘***’相同性别的所有学生信息。
将代码和运行结果硬拷贝到下面:要求:修改sqlplus默认提示符为本人的姓名全称,方法举例如下:set sqlprompt liangyongxian>三、数据库对象(本大题共4小题,每题5分,总计20分)(1)创建一个视图,视图上看到的数据包括:性别和该性别的平均年龄。
Oracle练习题1.向LOCATION表中插入以下2条数据1)区域编号1(自动生成),大连Insert into location values(seq_location.nextval,’大连’);2)区域编号2(自动生成),Insert into location values(seq_location.nextval);2.查询LOCATION表中的所有区域编号Select location_id from location;3.向DEPARTMENT表中插入以下2条数据1)部门编号1(自动生成),教学部,查询区域所在地是大连的该区域编号Insert into department values(seq_department.nextval,’教学部’,(select location_id from location where city =‘大连’));2)部门编号2(自动生成),市场部,区域编号2Insert into department values(seq_department.nextval,’市场部’,2);4.查询DEPARTMENT表中的所有部门编号Select department_name form department;5.向EMPLOYEES表中插入以下2条数据1)雇员编号1(自动生成),张三,部门编号1,teacher1,3000,2006-9-5,aa@ Insert into employees values(seq_employees.nextval,‘张三’,1,’teacher1’,3000,to_date(’2006-9-5’,’yyyy-mm-dd’),’aa@’);2)雇员编号2(自动生成),李四,部门编号2,agora1,2500,2006-9-5,,82365421 Insert into employees values(seq_employees.nextval,’李四’,2,’agoral’,2500,to_date(‘2006-9-5’,’yyyy-mm-dd’),82365421);6.查询EMPLOYEES表中所有的数据Select * from employees;7.查询EMPLOYEES表中薪水大于2500的所有数据select * from employees where salary > 2500;8.查询EMPLOYEES表中薪水大于等于2500的所有数据Select * from employees where salary>=2500;9.查询EMPLOYEES表中薪水小于2500的所有数据Select * from employees where salary < 2500;10.查询EMPLOYEES表中薪水小于等于2500的所有数据Select * from employees where salary < =2500;11.查询EMPLOYEES表中薪水不等于2500的所有数据(要求2种写法)Select * from employees where salary != 2500;Select * from employees where salary <> 2500;12.查询EMPLOYEES表中雇员编号在1~10之间的所有数据,包括1和10Select * from employees where employees_id between 1 and 10;13.查询EMPLOYEES表中雇员编号不是2的所有雇员信息Select * from employees where employees_id <>2;14.查询EMPLOYEES表中雇员姓名中第二个字是“三”的雇员的所有信息Select * from employees where last_name like ‘_三%’;15.查询EMPLOYEES表中电话为空的雇员的所有信息Select * from employees where phone_number is null;16.查询EMPLOYEES表中现有数据的个数Select count(*) from employees;17.查询EMPLOYEES表中最大薪水值Select max(salary) from employees;18.查询EMPLOYEES表中最小薪水值Select min(salary) from employees;19.查询EMPLOYEES表中薪水的平均值Select avg(salary) from employees;20.查询EMPLOYEES表中所有薪水的和Select sum(salary) from employees;21.查询EMPLOYEES表中部门的编号和该部门的平均薪水(使用分组查询)Select department_id,avg(salary) from employees group by department_id;22.查询EMPLOYEES表中的所有信息,要求根据雇员姓名倒序排列Select * from employees order by last_name desc;23.把雇员姓名为“张三”的工资涨到3500,把工资为2500的雇员的工资涨到3000Update employees set salary=3500 where last_name like ‘张三’;Update employees set salary=3000 where salary=2500;24.根据区域编号2查询LOCATION表中该区域所在的城市,如果结果为空值则用“大连”来代替Select nvl(city,’大连’) from location where location_id=2;25.根据雇员姓名为“张三”的查询EMPLOYEES表中该雇员的工作编号,并以此作为条件查询EMPLOYEES表中该雇员的姓名、工作编号、薪水等信息(使用子查询)Select last_name,job_id,salary from employees where job_id=(select job_id from employees where last_name like ‘张三’);26.查询EMPLOYEES表中的最少薪水,并根据这个结果查询EMPLOYEES表中薪水等于这个值的雇员编号、姓名、工作编号和薪水等信息(使用子查询)Select employees_id,employees_name,job_id,salary from employees where salary=(select min(salary) from employees);27.查询EMPLOYEES表中的雇员编号、姓名、部门编号和DEPARTMENT表中的部门编号、部门名称、部门所在的区域编号(使用2表连接)Selecte.employees_id,st_name,e.department_id,d.department_id,department_name,location_idFrom employees e join department d on e.department_id=d.department_id ;28.查询EMPLOYEES表中的雇员编号、姓名、部门编号和DEPARTMENT表中的部门编号、部门名称、部门所在的区域编号以及LOCATION表中的区域编号、该区域所在的城市(使用多表连接)select e.employees_id, st_name, e.department_id, d.department_id, d.department_name,d.location_id, l.location_id, l.city from employees e, department d, location l wheree.department_id=d.department_id and d.location_id=l.location_id29.查询EMPLOYEES表中的雇员姓名、部门编号和DEPARTMENT表中的部门名称(使用左连接)select st_name, e.department_id, d.department_name from employees e left join department d on e.department_id=d.department_id30.查询EMPLOYEES表中的雇员姓名、部门编号和DEPARTMENT表中的部门名称(使用右连接)select st_name, e.department_id, d.department_name from employees e right join department d on e.department_id=d.department_id1.查询地点编号为1的城市Select city from location where location_id=1;2.查询工资在2000-5000之间的员工的信息Select * from employees where salary between 2000 and 5000;3.查询‘张三’所在的部门名称Select department_name from department where department_id=(select department_id from employees where last_name = ‘张三’ );4.查询每个雇员的的姓名,部门名称,工作地点5.统计每个职位(job_id)的人数Select count(*) from employees where job_id=’agoral’;Select count(*) from employees where job_id=’teacher1’;6查询location表中的全部数据Select * from location;7 删除email为“aa@”的员工记录Delete * from employees where email=’aa@’;8查询job_id为teacher1的姓名及工资。
Select last_name,salary from employees where job_id=’teacher1’;9将所有job_id为” president”的工资增加100。
Update employees set salary=salary+100 where job_id=’president’;10查询部门名称中带有“大连”字样的部门的名称Select department_name from department where department_name like ‘%大连%’;11查询系统当前日期,以及seq_location的下一个值Select location_id from location where location_id > seq_location desc limit 1;12’mouse’部门的平均工资。