学号姓名Oracle练习题

合集下载

oracle练习

oracle练习

函数练习
1.将字符串“study sql”使用替换函数改成 study oracle 2.计算2的8次幂 3.求20除以7的余数 4.从”I love you” 中取得”love” 5.计算2009-2 月-4与现在日期相差的月份个 数
视图索引
1.创建视图,在视图中包含的字段有:学号, 姓名,性别,出身日期,所在班级名称。 2.创建视图,在视图中包含的字段有:学号, 姓名,课程名称,成绩 3.创建成绩表的索引,按照课程编号的升序 和成绩的降序排序 4.创建学生表索引,按照班级编号降序排序
触发器
1.对成绩表创建触发器,当在表中插入数据 时,限制插入的成绩不能大于100分 2.对班级表创建触发器,当更新班级编号为 001的班级信息时,不允许更新。
Oracle练习题

表的创建: 1.使用命令创建学生表,表结构如下: 学生表(学号,姓名,性别,出生日期,班 级编号) 班级表(班级编号,班级名称) 2.使用企业管理器创建表 课程表(课程编号,课程名称) 成绩表(学号,课程编号,成绩)

表操作
3.数据表的操作 1)使用命令修改学生表的表结构,增加一个新的字段籍贯 2)为性别字段添加约束 3)使用命令添加数据到四张表中 4.实行如下的查询 1)查询学生表中的性别为女同学的信息 2)查询男女同学的人数 3)查询各个班级的人数据 4)查询课程号为01的学生成绩并且按照成绩的相机排序 5)查询数学课程的平均成绩 6)查询课程号为01课程中成绩高平均分的学生信息 7)将课程号为02课程的成绩都加10分 8)删除名称为计算机技术的班级 9)查询学生信息,查询结果的字段有学号,姓名,年龄 10)查询选修了03课程,切是男同学的学生信息
程序
1.接受2个数相除,并显示结果,如果除数为 0,则显示错误提示 2.输出九九乘法表

oracle练习及答案

oracle练习及答案

--7、以class降序显示student表的所有记录。 select * from student1 order by class desc;
--8、以cno升序、degree降序显示score表的所有记录。
select * from score1 order by cno asc ,degree desc;
95033 95033r(老师信息表) tno 804 856 825 831 833 tname 李诚 李旭 王萍 刘冰 王超 sex 男 男 女 女 男 birthday 12/02/58 03/12/69 05/05/72 08/14/77 02/12/61 prof 副教授 讲师 助教 助教 教授 depart 计算机系 电子工程系 计算机系 电子工程系 计算机系
--11、显示“3-105”号课程的平均分。
select avg(degree) from score1 where cno='3-105';
--12、显示score表中至少有5名学生选修的并以3开头的课程 号的平均分数. select avg(degree) from score1 where cno like '3%';
--9、显示“95031”班的学生人数。 select class, count(*) from student1 group by class having class=95031;
副标题
请写出下列查询语句并给出结果
--10、显示score表中的最高分的学生学号和课程号。
select sno,cno from score1 where degree=(select max(degree) from score1);

Oracle测试题及答案.doc

Oracle测试题及答案.doc
if s=:new.bno then
insert into borrow_save
values(:o,:new.bno,:new.rdate);
end if;
end;
/
12.建立一个视图,显示“力01”班学生的借书信息(只要求显示姓名和书名)。
create view ca_view as
解决两个写事务冲突的办法就是采用“加锁”机制。例如A、B两个事务同吋对一个表的某航数据进行修改,A事务首先修改时对该数据加锁,禁止其他事务对该数据的修改。只有当A事务完成修改工作、并将锁打开后,其他事物才被允许修改。这时候等待的B事务才可以对该数据进行修改。锁可以防止两个写事务同时对一个数裾进行修改,所以也就不会出现写丢失的错误。
11.在borrow表上建立一个触发器,完成如下功能:如果读者借阅的书名是“数据库技术及应用”,就将该读者的借阅记录保存在borrow_save表中(注:borrow_save表结构同borrow表)。
create table borrow_save as
(select * from borrow)
借书卡card (eno卡号,name姓名,class班级)
图书books (bno书号,bname书名,author作者,price单价,quantity库存册数)借书记录borrow (eno借书卡号,bno书号,rdate还书曰期)
注:限定每人每种书只能借一本;库存册数随借书、还书而改变。
1.写出建立borrow表的SQL语句,要求定义主码完整性约束和引用完整性约束create table card
mark INTEGER;
BEGIN
BEGIN//嵌套块1
select氺into tin_rec from tin ;

oracle综合题

oracle综合题

三、综合题(共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练习题习题答案张表题

Oracle练习题习题答案张表题

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)(共5篇)

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习题二

oracle习题二

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考试题

Oracle考试题

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,该表中有职务列。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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’部门的平均工资。

相关文档
最新文档