技术笔试面试题(下)

【题目编号】 jsd-02-201-5017
【知 识 点】 数据库-Oracle SQL-级联删除、左外连接、SQL基础
【难易程度】 50
【题目描述】
STOMERS表,字段为:ID:(非空,主键)bigint,NAME:(非空)varchar,AGE:int类型;创建ORDERS表,字段为:ID:(非空,主键,)bigint,ORDER_NUMBER:(非空)varchar,PRICE:double,CUSTOMER_ID :(外键)bigint,设置级连删除;

  1. 使用左外连接查询,ORDERS 和 CUSTOMERS 表,
  2. delete from tablea & truncate table tablea的区别
    【正确答案】
    create table CUSTOMBERS(
    ID bigint not null,
    NAME varchar(15),
    AGE int,
    primary key (ID)
    );
    create table ORDERS(
    ID bigint not null,
    ORDER_NUMBER varchar(15) not nulll,
    PRICE double precision,
    CUSTOMER_ID bigint,
    primary key(ID),
    );
    alter table ORDERS add constraint FK_CUSTOMER foreign key (CUSTOMER_ID) references CUSTOMERS(ID) on delete cascade;

select c.ID, o.CUSTOMER_ID,c.NAME, o.ID ORDER_ID,ORDER_NUMBER from CUSTOMERS c leftouter join ORDERS o no c.ID=o.CUSTOMER_ID;
2) truncate 语句执行速度快,占资源少,并且只记录页删除的日志;
delete 对每条记录的删除均需要记录日志
【解释】无

【题目编号】 jsd-02-201-5018
【知 识 点】 数据库-Oracle SQL-高级查询-子查询、关联查询-内连接
【难易程度】 30
【题目描述】表1:book表,字段有id(主键),name (书名);
表2:bookEnrol表(图书借出归还登记),字段有id,bookId(外键),dependDate(变更时间),state(1.借出 2.归还)。
id name
1 English
2 Math
3 JAVA
(表1)
id bookId dependDate State
1 1 2009-01-02 1
2 1 2009-01-02 2
3 2 2009-01-14 1
4 1 2009-01-17 1
5 2 2009-02-14 2
6 2 2009-02-15 1
7 3 2009-02-18 1
8 3 2009-02-19 2
(表2)
1) 要求查询结果应为:(查询出被借出的书和被借出的日期)
id name dependDate
1 English 2009-01-17
2 Math 2009-02-15
2) 第二个表是用来登记的,不管你是借还是还,都要添加一条记录。
请写一个SQL语句,获取到现在状态为已借出的所有图书的相关信息。
【正确答案】
1)
/方案一/
select a.id,a.name,b. dependDate from book a, bookEnrol b where
a.id=b.bookId
and
b. dependDate in(select max(dependDate) from bookEnrol group by bookId )
and b.State =1

/方案二/
select k.id,k.name,a. dependDate
from bookEnrol a, book k
where a.id in (select max(b.id) from bookEnrol b group by b.bookId)
and a.state = 1
and a.bookId = k.id;
2)
select book.id,book.name,max(dependDate)
from book inner join bookEnrol on book.id=bookEnrol.bookid AND booker.state=1
group by book.id ;
【解释】无

【题目编号】 jsd-02-201-5019
【知 识 点】 数据库-Oracle SQL-SQL基础-分组
【难易程度】 10
【题目描述】
查询语句排名问题:
名次 姓名 月积分(char) 总积分(char)
1 WhatIsJava 1 99
2 水王 76 981
3 新浪网 65 96
4 牛人 22 9
5 中国队 64 89
6 北林信息 66 66
7 加太阳 53 66
8 中成药 11 33
9 西洋参 25 26
10 大拿 33 23
如果用总积分做降序排序,因为总积分是字符型,所以排出来是这样子(9,8,7,6,5…),要求按照总积分的数字大小排序。
【正确答案】
select * from tablename order by cast(总积分 as int) desc
【解释】无

【题目编号】 jsd-02-201-5020
【知 识 点】 数据库-Oracle SQL-SQL基础、高级查询
【难易程度】 40
【题目描述】
按要求写 SQL 语句:根据集团成员培训业务,建立以下三张表:
S (S#,SN,SD,SA) S#,SN,SD,SA 分别代表学号、学员姓名、所属单位、学员年龄
C (C#,CN ) C#,CN 分别代表课程编号、课程名称
SC ( S#,C#,G ) S#,C#,G 分别代表学号、所选修的课程编号、学习成绩 要求如下:
1)使用标准 SQL 语句查询成员名单中所属单位叫“技术一部”的人员总数及平均年龄;
2)使用标准的 SQL 语句更新学号为‘S#1’的姓名为“Mike”;
3)使用嵌套语句查询选修课程编号为‘C2’的学员姓名和所属单位;
4)使用嵌套语句查询不选修课程编号为‘C5’的学员姓名和所属单位;
5)查询选修课程超过 5 门的学员学号和所属单位;
【正确答案】

  1. select count(SN),avg(SA) from S where SD=‘技术一部’;
  2. update S set SN=‘Mike’ where S#=‘S#1’;
  3. select SN,SD from S where S#=(select S# from SC where C#=‘C2’);
  4. select SN,SD from S where S# not in(select S# from SC where C#=‘C5’);
  5. select S#,SD from S where S#=
    (select S# from SC group by S# having count(S#)>=5);
    【解释】无

【题目编号】 jsd-02-201-5021
【知 识 点】 数据库-Oracle SQL-关联查询
【难易程度】 50
【题目描述】
请根据以下四张表(其中 course_t 表的 teacher_id 字段是 teacher_t 表的 id 字段的外键引用), 拼写出相应的 sql 语句(oracle 语法)。
学生表:students_t
id name sex
001 赵学生 Male
002 钱学生 Male
003 孙学生 Male
004 李学生 Female
005 周学生 Female
? ? ?

教师表:teacher_t
id name sex
001 吴老师 Male
002 郑老师 Male
003 王老师 Male
004 刘老师 Female
005 张老师 Female

课程表:course_t
id name credit teacher_id
001 语文 3 001
002 数学 3 002
003 英语 4 003
004 物理 3 004
005 化学 2 005
006 政治 1 001
007 生物 1 005
008 计算机 2 005

选课表:student_course_t
id student_id course_id
001 001 001
002 001 002
003 001 003
004 002 001
005 002 007
? ? ?
1)统计每个学生选修的学分,并按学分降序排序
2)统计每个学生选修的所有课程和对应的任课老师;并按学生 Id 和课程 Id 排序
3)统计所有学生、所有课程和所有任课老师的对应关系;并按学生 Id 和课程 Id 排序
【正确答案】
1)select sc.student_id,count(c.credit)
from students_t s, course_t c, student_course_t sc
where s.id=sc.student_id and c.id=sc.course_id group by sc.student_id order by
count(c.credit);
2) select s.name as s_name,c.name as c_name ,t.name as t_name from students_t s, course_t c, student_course_t sc,teacher_t t
where s.id=sc.student_id and c.id=sc.course_id and t.id=c.teacher_id order by s.id,c.id;
3)与 2)相同
【解释】无

【题目编号】 jsd-02-201-5022
【知 识 点】 数据库-Oracle SQL-SQL基础-基本查询语句
【难易程度】 10
【题目描述】
已有“成绩”如下表所示:
学号 课程号 分数
S1 C1 80
S1 C2 75
S2 C1 null
S2 C2 55
S3 C3 90
1) 执行 SQL 语句:Select Count(学号)From 成绩 Where 分数〉60后的结果是什么?
2)请写出 SQL 语句来进行查询“成绩”表中学号为 S1、课程号为 C2 的学号和分数
【正确答案】
1)统计分数超过 60 的学生总数。
2)select 学号,分数 from 成绩 where 学号=‘S1 and 课程号=‘C2’;
【解释】无

【题目编号】 jsd-02-201-5023
【知 识 点】 数据库-Oracle SQL-索引
【难易程度】 20
【题目描述】
SAL 是 Product 表中的索引列,请优化如下 SQL 语句,并简述原因。原语句:
SELECT*
FROM Product
WHERE SAL * 12 〉25000;
【正确答案】
Select * from product where sal>(25000/12);
【解释】无
WHERE 子句中,如果索引列是函数的一部分.优化器将不使用索引而使用全表扫描.

【题目编号】 jsd-02-201-5024
【知 识 点】 数据库-Oracle SQL-SQL基础-分组
【难易程度】 20
【题目描述】
有一张表,字段有用户名、口令及备注,请用 SQL 选择出用户名和口令完全相同的记录(应包括用户名和数量的出现次数)
T_USER(USER_NAME,PASSWORD)
显示
USER_NAME COUNT() QWE 4
WER 5
【正确答案】
select user_name,count(
) from t_user group by user_name,password;
【解释】无

【题目编号】 jsd-02-201-5025
【知 识 点】 数据库-Oracle SQL-关联查询-子查询
【难易程度】 40
【题目描述】
有一张表,T_MONEY,字段有 ID,FEE,请用 SQL 语言选择出 FEE 值为前三条记录。
T_MONEY(ID,FEE)
显示
ID FEE
2 100
1 90
2 80
【正确答案】
Select Id,fee from (Select id,fee from t_money order by fee desc) where rownum<=3;
【解释】无

【题目编号】 jsd-02-201-5026
【知 识 点】 数据库-Oracle SQL-高级查询-子查询、排序函数-RUWNUMBER
【难易程度】 40
【题目描述】
table_name temp
Id name
1 a
2 b
3 a
4 a
结果为
Id name
1 a
2 b
写出 sql 语句。
【正确答案】
select rownum as id , name from(select distinct name from temp);
【解释】无

【题目编号】 jsd-02-201-5027
【知 识 点】 数据库-Oracle SQL-SQL基础-聚合函数
【难易程度】 50
【题目描述】
已知原表(t_salary)
year salary
2000 1000
2001 2000
2002 3000
2003 4000
先要实现显示结果(salary 为以前的工资和)
year salary
2000 1000
2001 3000
2002 6000
写出 sql 语句。
【正确答案】
select t.year, sum(t.salary) over (order by t.year) as sum_salary from salary_t t;
【解释】无

【题目编号】 jsd-02-201-5028
【知 识 点】 数据库-Oracle SQL-SQL基础-表操作
【难易程度】 60
【题目描述】
有两个表 A 和 B,均有 key 和 value 两个字段,如果 B 的 key 在 A 中也有,就把 B 的 value 换为 A中对应的 value。这道题的 SQL 语句怎么写?
【正确答案】
merge into A a using B b
on (a.key=b.key) when matched then update set a.value=b.value
【解释】无

【题目编号】 jsd-02-201-5029
【知 识 点】 数据库-Oracle SQL-SQL基础-表操作、SQL基础-聚合函数
【难易程度】 30
【题目描述】
创建一张数据表,并插入如下数据。
购物人 商品名称 数量
A 甲 2
B 乙 4
C 丙 1
A 乙 2
B 丙 5
1)写出创建表和插入内容的 sql 语句
2)写出 sql 语句使其产生如下结果
购物人 商品甲 商品乙 商品丙
A 2 2 Null
B Null 4 5
C Null Null 1
【正确答案】
create table tb_order( customer varchar2(20), product_name varchar2(20), quantity number(2) )
Insert into tb_order(customer,product_name,quantity)values(‘A’,’甲’,2);
Insert into tb_order(customer,product_name,quantity)values(‘B’,’乙’,4);
Insert into tb_order(customer,product_name,quantity)values(‘C’,’丙’,1);
Insert into tb_order(customer,product_name,quantity)values(‘A’,’甲’,2);
Insert into tb_order(customer,product_name,quantity)values(‘B’,’乙’,5);

2)select customer “购物人”, sum(decode(product_name,‘甲’,quantity,0)) “商品甲”, sum(decode(product_name,‘乙’,quantity,0)) “商品乙”, sum(decode(product_name,‘丙’,quantity,0)) “商品丙” from tb_order group by customer;
【解释】无

【题目编号】 jsd-02-201-5030
【知 识 点】 数据库-Oracle SQL-关联查询-等值连接
【难易程度】 20
【题目描述】
有如下两张表:部门表和职员表,每个职员都属于一个部门,表结构如下:
Dept 表
Deptno Deptname
? ?
Emp 表
Empno Empname Deptno
? ? ?
请使用 SQL 语句查询每个部门有多少职员,要求查询结果包含两例(部门名称,人数)?
【正确答案】
select d.deptname,count(*) from dept d,emp e where d.deptno=e.deptno
group by d.deptno,d.deptname;
【解释】无

【题目编号】 jsd-02-201-5031
【知 识 点】 数据库-Oracle SQL-关联查询-内连接、等值连接
【难易程度】 50
【题目描述】
业务场景:存在下面的表及记录
GOODS(进货表)
GOODSID(主键) GOODSNAME MEMO
1 青霉素
2 西瓜霜
3 创可贴
4 西洋参
SU(进货表)
GOODSID(主键) SUQTY
1 60
2 70
SA(销售表)
GOODSID(主键) SAQTY
3 80
4 90
要求一:进货记录,给出 SQL 达到以下结果
GOODSID(主键) GOODSNAME SUQTY
1 青霉素 60
2 西瓜霜 70
3 创可贴 0
4 西洋参 0
要求二:进销对比,给出 SQL 达到以下结果
GOODSID(主键) GOODSNAME SUQTY SAQTY
1 青霉素 60 0
2 西瓜霜 70 70
3 创可贴 0 80
要求三:将 GOODS.MEMO 更新为[进货数量 SU.SUQTY]
【正确答案】
1)select g.goodsid,g.goodsname,s.quqty
from goods g inner join su s on g.goodsid=s.goodsid;
2 ) select g.goodsid,g.goodsname,s.quqty,a.saqty
From goods g, su s,sa a on g.goodsid=s.goodsid and g.goodsid=a.goodsid;
3)update goods set demo=(select s.suqty from su s where s.goodsId=goods.goodsId)
【解释】无

【题目编号】 jsd-02-201-5032
【知 识 点】 数据库-Oracle SQL-SQL基础-表操作、SQL基础-聚合函数、关联查询-内连接
【难易程度】 50
【题目描述】
表结构:

  1. 表名:apply
    字段(字段名/类型/长度):
    applyno varchar 8;//申请单号(关键字)
    applydate bigint 8;//申请日期
    state varchar 2;//申请状态
  2. 表名:applydetail
    字段(字段名/类型/长度):
    applyno varchar 8;//申请单号(关键字)
    name varchar 30;//申请人姓名
    idcard varchar 18;//申请人身份证号 state varchar 2;//申请状态 其中,两个表的关联字段为申请单号。
    题目:
    1)查询身份证号码为 440401430103082 的申请日期
    2)查询同一个身份证号码有两条以上记录的身份证号码及记录个数
    3)删除 applydetail 表中所有姓李的记录
    【正确答案】
  3. Select applydate from apply a join applydetail d on a.applyno=d.applyno and
    Idcard=‘440401430103082’;
  4. select idcard,count() from applydetail group by idcard having count()>2;
  5. delete from applydetail where name=‘李%’;
    【解释】无

【题目编号】 jsd-02-201-5033
【知 识 点】 数据库-Oracle SQL-SQL基础-表操作
【难易程度】 20
【题目描述】
在 system 方案中建立表 table1,表中包含如下字段 字段名称 数据类型 要求
name Varchar2 非空 id Number 非空 age Number sex Varchar2 salary Number
【正确答案】
Create table system.tablel1 ( Id number not null,
Name varchar(8) not null, Age number,
Sex varchar(2), Salary number);
【解释】无

【题目编号】 jsd-02-201-5034
【知 识 点】 数据库-Oracle SQL-SQL基础
【难易程度】 70
【题目描述】
某公司的机构结构为树型结构,对应的表结构为TableCompany(ComCode—机构代码, UpperComCode—上级机构代码),如何查询出总公司的所有下级机构?(java 或者 SQL 均可)。你觉得这种思维和设计是否合理?有什么好建议的?
【正确答案】
select t1.* from TableCompany t1, TableCompany t2
Where t1.ComCode = t2.UpperComCode
这种设计比较容易让人理解,但是表中的数据联系过于紧密,数据量很大,会给后期维护造成不便,如果根据第三范式要求,将每一子公司独立成一张表,对于关系的维护和数据的管理都会变得比较方便。
【解释】无

【题目编号】 jsd-02-201-5035
【知 识 点】 数据库-Oracle SQL-SQL基础-表操作
【难易程度】 40
【题目描述】
一个简单的论坛系统,以数据库存储如下数据: 用户名,发帖标题,发帖内容,回复标题,回复内容。 每天论坛访问量 200 万左右,更新帖子 10 万左右。 请给出数据库表结构设计,并结合范式简要说明设计思路。
【正确答案】
用户表:存储用户信息;
用户所发的帖子表:存储用户所发的帖子; 回复表:存储对帖子所做的回复。
设计:
User:
Create table tb_user(
id number(10) primary key,
Uname varchar2(20) not null unique
);

Comments:
Create table tb_comments(
id number(10),
comments_id number(20) not null unique, title varchar2(20) not null,
comments varchar2(255) not null,
foreign key(id) references tb_user(id)
);

Replay:
Create table tb_replay(
id number(10),
comments varchar2(255) not null,
foreign key(id) references tb_comments(comments_id)
);
思路:因为此应用所要存储的数据量比较大,所以为了避免数据的冗余,表的设计依托于第三范式。
【解释】无

【题目编号】 jsd-02-201-5036
【知 识 点】 数据库-Oracle SQL-高级查询-子查询
【难易程度】 40
【题目描述】
有一个数据表 userinfo,包含 userid,username 字段,其中 userid 是唯一的,username 可能 重复,请写一句 sql 查询语句,把重复的记录全部取出来。
userid username
1 老王
2 老王
3 老李
4 老李
5 小张 要求返回记录集 userid username
1 老王
2 老王
3 老李
4 老李
【正确答案】
select * from userinfo where username in (select username from userinfo group by username having count(username)>1);
【解释】无

【题目编号】 jsd-02-201-5037
【知 识 点】 数据库-Oracle SQL-SQL基础-表操作
【难易程度】 20
【题目描述】
数据库基础:
1)使用 SQL 语句创建学生表 students
字段: 学号:s_id 姓名:s_name 年龄:age 班级:class 辅导员:assistant (请设计各字段类型 与长度)
2)查询学生表中年龄大于 20 的所有学生的学号与姓名
3)删除 0201 班的所有同学
4)查询 0302 班姓李的学生的个数
5)将班编号以’02’开头的所有班级的辅导员修改为‘李四’
【正确答案】
1)create table students(s_id number(10) primary key, s_name varchar(30) not null,
age number(3) not null, class varchar(20) not null, assistant varchar(30));
2)select s_id,s_name from students where age>20;
3)delete from students where class=’0201’;
4)select count(s_name) from students
where s_name like ‘李%’ and class=‘0302’;
5)update students set assistant=‘李四’ where class like ‘02%’;
【解释】无

【题目编号】 jsd-02-201-5038
【知 识 点】 数据库-Oracle SQL-SQL基础-分组
【难易程度】 30
【题目描述】
表名:高考信息表 students_info
准考证号 科目 成绩
no subject score
2006001 语文 119
2006001 数学 108
2006002 物理 142
2006001 化学 136
2006001 物理 127
2006002 数学 149
2006002 英语 110
2006002 语文 105
2006001 英语 98
2006002 化学 129
写出高考总分在 600 以上的学生准考证号的 SQL
【正确答案】
select no
from students_info group by no
having sum(score)>600;
【解释】无

【题目编号】 jsd-02-201-5039
【知 识 点】 数据库-Oracle SQL-高级查询-子查询
【难易程度】 50
【题目描述】
有一个表 LEANR,表里有三个字段分别是学号(student_id),
课程(kc),成绩(grade)。
1).查询每一门课程的前两名
2).查询以 Grade 降序排列的第 31 至 40 条记录(不需要区分课程)
3).查询表中存在课程重复 4 次以上的记录,显示课程和重复的次数,并且按照重复次数的降序排列
【正确答案】
1).select student_id,kc,grade
from (select student_id,kc,grade,
row_number() over(partition by kc order by grade desc)rn from LEANR)
where rn<=2;
2)select student_id,grade from (
select lea.*,rownum rm from (
select * from LEANR order by grade desc
) lea
where rownum < 41
) where rm between 31 and 40;
3). select kc,count(kc)
from LEANR
group by kc
having count(kc)>=2
order by count(kc) desc;
【解释】无

【题目编号】 jsd-02-201-5040
【知 识 点】 数据库-Oracle SQL-关联查询-等值连接
【难易程度】
【题目描述】
a 部门表 b 员工表
a 表字段( id --部门编号 departmentName-部门名称 ) b 表字段( id–部门编号 employee- 员工名称 ) 问题:如何一条 sql 语句查询出每个部门共有多少人
【正确答案】
create table a(
id number primary key, departmentName varchar(20)
);
create table b(
id number,
employee varchar(20)
);
insert into a values(1,‘部门 1’);
insert into a values(2,‘部门 2’);
insert into a values(3,‘部门 3’);
insert into b values(1,‘emp1’);
insert into b values(1,‘emp2’);
insert into b values(1,‘emp3’);
insert into b values(2,‘emp4’);
insert into b values(2,‘emp5’);
insert into b values(3,‘emp6’);
select departmentName,count(employee) from a,b
where a.id=b.id group by departmentName;
【解释】无

【题目编号】 jsd-02-201-5041
【知 识 点】 数据库-Oracle SQL-关联查询-等值连接、高级查询-子查询
【难易程度】 40
【题目描述】
为管理岗位业务培训信息,建立 3 个表:
S (SID,SN,SD,SA) SID,SN,SD,SA 分别代表学号、学员姓名、所属单位、学员年龄
C (CID,CN ) CID,CN 分别代表课程编号、课程名称
SC ( SID,CID,G ) SID,CID,G 分别代表学号、所选修的课程编号、学习成绩

  1. 使用标准 SQL 嵌套语句查询选修课程名称为’税收基础’的学员学号和姓名
  2. 使用标准 SQL 嵌套语句查询选修课程编号为’02’的学员姓名和所属单位
  3. 使用标准 SQL 嵌套语句查询不选修课程编号为’03’的学员姓名和所属单位
  4. 使用标准 SQL 嵌套语句查询选修全部课程的学员姓名和所属单位
  5. 查询选修课程超过 5 门的学员学号和所属单位
    【正确答案】
    create table s(
    sid int(10) primary key, sn varchar(20) not null, sd varchar(20) not null, sa int(3) not null
    );
    create table c(
    cid int(10) primary key, cn varchar(20) not null
    );
    create table sc(
    sid int(10) references s(sid), cid int(10) references c(cid), g int(10),
    primary key(sid,cid)
    );
    insert into s values(1,“zhangsan”,“project”,25);
    insert into s values(2,“lisi”,“mis”,26);
    insert into s values(3,“wangwu”,“manager”,27);
    insert into s values(4,“zhaoliu”,“mis”,26);
    insert into c values(01,“税收基础”);
    insert into c values(02,“Core Java”);
    insert into c values(03,“NetWork”);
    insert into sc values(1,01,70);
    insert into sc values(1,02,75); insert into sc values(1,03,80);
    insert into sc values(2,01,80); insert into sc values(2,03,69);
    insert into sc values(3,02,73);
    1)
    select s.sid,s.sn from s,c,sc
    where s.sid=sc.sid and c.cid=sc.cid
    and c.name=‘税收基础’;
  1. select a.sn,a.sd from s a, c b
    where b.cid in(select c.cid from sc c where a.sid=c.sid and b.cid=c.cid)
    and b.cid=02;
  2. select a.sn,a.sd from s a, c b
    where b.cid not in(select c.cid from sc c where a.sid=c.sid and b.cid=c.cid)
    and b.cid=03;
  3. select sn,sd
    from s where sid in
    (select sid from sc group by sid having count(cid)=(select count(cid) from c));
  4. select sn,sd from s
    where sid in(select sid from sc group by sid having count(distinct cid)>5);

【解释】无

【题目编号】 jsd-02-201-5042
【知 识 点】 数据库-Oracle SQL-SQL基础-表操作、java代码
【难易程度】 60
【题目描述】
请根据以下要求来完成题目: 会议室预定模块:某公司有多个会议室,以房间号区分。如果某部门需要预定会议室,则会提交预定请求(包含预定开始使用时间、预定结束使用,所预定会议室房间号)。 设计一个表,保存会议室预定信息。
要求采用 SQL 语句及JAVA 代码段判断在 2003-3-10 下午 3:00~4:00 3 号会议室是否空闲。 请写出有关 SQL 语句以及相关 JAVA 的代码段。
【正确答案】
1)Sql 语句:
create table meeting(
id number primary key , room_id varchar(10), isUsed char,
begin timestamp, end timestamp
);
insert into meeting values(
1,‘201’,1,to_date(‘2003-03-10 15:00:00’,‘yyyy-mm-dd hh24:mi:ss’)
,to_date(‘2003-03-10 16:00:00’,‘yyyy-mm-dd hh24:mi:ss’));
insert into meeting values(
2,‘201’,1,to_date(‘2003-03-10 17:00:00’,‘yyyy-mm-dd hh24:mi:ss’)
,to_date(‘2003-03-10 22:00:00’,‘yyyy-mm-dd hh24:mi:ss’));
2)
package com.tarena;
import java.sql.*;
public class Test {
public static void main(String[] args) {
String driverName = “oracle.jdbc.OracleDriver”;
String url = “jdbc:oracle:thin:@127.0.0.1:1521:orcl”;
String username = “scott”;
String pwd = “tiger”;
Connection con = null; Statement stmt = null; ResultSet rs = null;
try {
Class.forName(driverName);
con = DriverManager.getConnection(url, username, pwd);
stmt = con.createStatement();
String sql = "select isUsed from " + “meeting "
+“where ((begin between to_date(
‘2003-03-10 15:00:00’,‘yyyy-mm-dd hh24:mi:ss’)
and to_date(‘2003-03-10 16:00:00’,‘yyyy-mm-dd hh24:mi:ss’)) "
+“or(end between to_date(
‘2003-03-10 15:00:00’,‘yyyy-mm-dd hh24:mi:ss’)
and to_date(‘2003-03-10 16:00:00’,‘yyyy-mm-dd hh24:mi:ss’)))”
+” and room_id=201”;
if (stmt.execute(sql)) {
rs = stmt.getResultSet();
}
StringBuffer sb = new StringBuffer();
while (rs.next()) {
sb.append(“isFree:” + rs.getInt(1) + " ");
} System.out.print(sb.toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
con.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
【解释】无

【题目编号】 jsd-02-201-5043
【知 识 点】 数据库-Oracle SQL-关联查询-等值连接
【难易程度】 40
【题目描述】
下面是两个数据库表,分别记录员工姓名和工资
T_EMPLOYEE
ID NAME
2 张三
3 李四
5 王五
??? ???

T_SALARY
ID SALARY
2 3400
3 4300
5 2500
??? ???
1.查询表 T_EMPLOYEE 中 id = 3 的员工记录
2.查询表 T_EMPLOYEE 中所有员工记录
3.联合查询表 T_EMPLOYEE 和 T_SALARY 中所有员工的姓名和工资记录,并按照薪水从高到低排列
【正确答案】
1).select * from t_employee where id = 3;
2).select * from t_employee;
3).select e.name,s.salary
from t_employee e,t_salary s where e.id=s.id
order by s.salary;
【解释】无

【题目编号】 jsd-02-201-5044
【知 识 点】 数据库-Oracle SQL-SQL基础-表操作
【难易程度】 40
【题目描述】
有三张表,学生表 S,课程表 C,学生课程表 SC,学生可以选修多门课程,一门课程可能被多个 学生选修,通过 SC 表关联。
1)写出建表以及插入语句;
2)写出 SQL 语句,查询选修了所有选修课程的学生;
3)写出 SQL 语句,查询选修了至少 2 门以上的课程的学生
【正确答案】

1)
create table student (id number(10) primary key,name varchar2(20));
create table course (id number(10) primary key,name varchar2(20));
create table sc(sid number(10) references student(id),cid number(10
references course(id),grade number(4,2));
insert into student values(1,‘feifei’); insert into student values(2,‘jingjing’);
insert into student values(3,‘nannan’); insert into student values(4,‘yuanyuan’);
insert into student values(5,‘jiejie’); insert into course values(1,‘corejava’);
insert into course values(2,‘c++’);insert into course values(3,‘jdbc’);
insert into course values(4,‘hibernate’); insert into sc values(1,1,98);
insert into sc values(2,1,97); insert into sc values(3,1,94); insert into sc values(4,1,92);
insert into sc values(5,1,93);insert into sc values(1,2,94);insert into sc values(2,2,92);
insert into sc values(3,2,95); insert into sc values(5,2,97); insert into sc values(1,3,92);
insert into sc values(2,3,92); insert into sc values(4,3,91); insert into sc values(1,4,99);
insert into sc values(3,4,89);
2)select sid,count() from sc group by sid having count()=(select count() from course);
3)select sid,count(
) from sc group by sid having count(*)>=2;
【解释】无

【题目编号】 jsd-02-201-5045
【知 识 点】 数据库-Oracle SQL-SQL基础、关联查询
【难易程度】 50
【题目描述】
SQL 题
–操作员表
select pkid,name,sys_corp_id ‘单位主键’ from base_operator
–角色表
select pkid,sys_corp_id ‘单位主键’,name from base_role
–角色与操作员的对应关系表
select pkid,base_role_id ‘角色主键’,base_operator_id ‘操作员主键’ from base_role_operator
–单位表
select pkid,name from sys_corps
–问题:
–1.显示出’开发’公司所拥有的操作员
–2.显示出’开发’公司每个角色所对应的操作员信息
–3.显示出’开发’公司每个角色所对应的操作员的个数
【正确答案】
答:1).Select name from base_operator;
2).Select op.pkid,op.name,op.sys_corp_id
From base_operator op,base_role_operator ro ,base_role br
Where ro.base_operator_id =op.pkid
And br.pkid=ro.base_role_id;
3).Select max(br.name) ,count(*)
From base_role_operator ro,base_role br
Where ro.base_role_id=br.pkid
Group by br.base_role_id;
【解释】无

【题目编号】 jsd-02-201-5046
【知 识 点】 数据库-Oracle SQL-SQL基础-表操作
【难易程度】 30
【题目描述】
说明在一个系统中权限管理中应该有哪些表、表间关系、各表哪些功能?
【正确答案】
角色和权限表是 m:n 的关系 操作表和权限表是 1:m 的关系模块表和操作表是 1:m 的关系表的大体设计如下:
– 角色表
create table roles (
id number primary key, name varchar2(20)
);
– 系统模块表
create table modules (
id number primary key, name varchar2(50), url varchar2(50)
);
– 模块操作表
create table operations (
id number primary key, name varchar2(20), mid number,
constraint foreign key (mid) references modules(id)
);
– 权限表
create table rights (
id number primary key,
name varchar2(20),
url varchar2(50),
operationid int references operations(id)
);
– 角色权限设置表
create table rolerights (
id number primary key,
roleid number references roles(id), rightid number references rights(id)
);
【解释】无

【题目编号】 jsd-02-201-5047
【知 识 点】 数据库-Oracle SQL-高级查询-子查询
【难易程度】 30
【题目描述】
说出下面语句的作用:
Select rownum,last_name,salary
From (select last_name,salary from s_emp order by salary desc) Where rownum<=10;
【正确答案】
选出 s_emp 表中工资前 10 名员工的姓名和工资。
【解释】无
2.2 PLSQL
【题目编号】 jsd-02-202-1001
【知 识 点】 数据库-PLSQL-程序流程控制-条件结构、循环结构
【难易程度】 60
【题目描述】
判断这 PL/SQL 代码块:BEGIN
FOR i IN 1…6 LOOP
IF i = 2 OR i = 3 THEN null; ELSE
INSERT INTO example(one) VALUES (i); END IF;
ROLLBACK; END LOOP; COMMIT; END;
有多少行被插入到表 EXAMPLE ?
【选项】
A. 0 B. 1 C. 2 D. 3
【正确答案】 A
【解释】
在循环结束前执行了 ROLLBACK 语句,数据被回滚。

【题目编号】 jsd-02-202-1002
【知 识 点】 数据库-PLSQL-程序结构
【难易程度】 50
【题目描述】
关于 PL/SQL 块的执行部分下列说法正确的是?
【选项】
A.PL/SQL 表达式可以包含分组函数.
B. PL/SQL 表达式不可以包含 SQL 函数.
C. 在 SQL 语句中部分分组函数可用.
D. 以上都不对
【正确答案】 A
【解释】无

【题目编号】 jsd-02-202-1003
【知 识 点】 数据库-PLSQL-程序结构
【难易程度】 50
【题目描述】
PL/SQL 的哪一部分实现对数据的操作?
【选项】
A. 头部分 B. 列外部分 C. 执行部分 D. 声明部分
【正确答案】 C
【解释】无

【题目编号】 jsd-02-202-1004
【知 识 点】 数据库-PLSQL-变量的声明与赋值
【难易程度】 60
【题目描述】
在 Oracle 中,执行如下 PL/SQL 语句后
CREATE TYPE car AS OBJECT
( id NUMBER, model VARCHAR2(25), color VARCHAR2(15) );
DECLARE
myvar car.model%TYPE; BEGIN
END;
变量 myvar 的数据类型为()。
【选项】
A.NUMBER B.car 类型 C.VARCHAR2 D.OBJECT
【正确答案】 C
【解释】
定义一个变量,其数据类型与已经定义的某个数据变量的类型相同,或者与数据库表的某个列的数据类型相同,这时可以使用%TYPE。

【题目编号】 jsd-02-202-1005
【知 识 点】 数据库-PLSQL-游标
【难易程度】 70
【题目描述】
表 CUSTOMER 包含如下列: CUSTOMER_ID NUMBER(9) ;LAST_NAME VARCHAR2(20) ;FIRST_NAME VARCHAR2(20) ;CREDIT_LIMIT NUMBER(9,2)
如下代码:
DECLARE
CURSOR cust_cursor IS
SELECT customer_id, last_name, first_name
FROM customer;
cust_rec cust_cursor%ROWTYPE;
你如何操纵 CUST_REC 中的记录?
【选项】
A.添加一个 LOOP 到游标声明中.
B.在 PL/SQL 块的执行部分,使用 INSERT INTO 语句.
C.在 PL/SQL 块的执行部分,使用一个 LOOP 和 FETCH 语句.
D.在 PL/SQL 块的执行部分,使用 SELECT 语句使用 INTO 操作.
【正确答案】 D
【解释】
%ROWTYPE 操作符, 返回一个记录类型, 其数据类型和数据库表的数据结构相一致,
在这里就和游标查询语句中的数据结果保持一致。例如:
DECLARE
CURSOR cust_cursor IS
SELECT CUSTOMER_ID, last_name, first_name
FROM customer;
cust_rec cust_cursor%ROWTYPE;
begin
open cust_cursor; LOOP
FETCH cust_cursor INTO cust_rec;
EXIT WHEN cust_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(cust_rec.last_name);
END LOOP;
end;

【题目编号】 jsd-02-202-1006
【知 识 点】 数据库-PLSQL-存储过程
【难易程度】 70
【题目描述】
定义存储过程如下:
CREATE OR REPLACE PROCEDURE INSERT_TEAM
(V_ID in NUMBER,V_CITY in VARCHER2 DEFAULT ‘AUSTIN’, V_NAME
in VARCHER2) IS
BEGIN
INSERT INTO TEAM (id, city,name) VALUES (v_id,v_city,v_name); COMMIT;
END;
以下哪些 PL/SQL 语句能够正确调用该过程?
【选项】
A. EXECUTE INSERT_TEAM;
B. EXECUTE INSERT_TEAM (V_NAME=.>“LONG HORNS”);
C. V_CITY=>“AUSTIN”;
D. EXECUTE INSERT_TEAM (3,“AUSTIN”,“LONG HORNS”)
【正确答案】 D
【解释】无

【题目编号】 jsd-02-202-1007
【知 识 点】 数据库-PLSQL-存储过程
【难易程度】 50
【题目描述】
关于存储过程参数,正确的说法是( )
【选项】
A. 存储过程的输出参数可以是标量类型,也可以是表类型。
A. 可以是表类型
B. 存储过程输入参数可以不输入信息而调用过程
C. 可以指定字符参数的字符长度(函数的()或者过程的(number/varchar2))
D. 以上说法都不对
【正确答案】 b
【解释】无

【题目编号】 jsd-02-202-1008
【知 识 点】 数据库-PLSQL-基本命令
【难易程度】 30
【题目描述】
PL/SQL块中不能直接使用的SQL命令是( )。
【选项】
A.SELECT B.INSERT C.UPDATE D.DROP
【正确答案】 D
【解释】无

【题目编号】 jsd-02-202-1009
【知 识 点】 数据库-PLSQL-程序结构
【难易程度】 60
【题目描述】
以下不属于命名的PL/SQL块的是( )。
【选项】
A.程序包 B.过程 C.游标 D.函数
【正确答案】 C
【解释】
游标充当一个指示返回多条记录集合中某一条的指针。不能单独的使用,不能被声明它以外的程序。

【题目编号】 jsd-02-202-1010
【知 识 点】 数据库-PLSQL-存储过程
【难易程度】 60
【题目描述】
()包用于显示PL/SQL块和存储过程中的调试信息。
【选项】
A.DBMS_OUTPUT B.DBMS_STANDARD
C.DBMS_INPUT D.DBMS_SESSION
【正确答案】 A
【解释】无

【题目编号】 jsd-02-202-1011
【知 识 点】 数据库-PLSQL-变量声明与赋值
【难易程度】 30
【题目描述】
在 PL/SQL 块的哪部分可以对初始变量赋予新值?
【选项】
A.结尾部分 B.开头部分 C.执行部分 D.声明部分
【正确答案】 C
【解释】无

【题目编号】 jsd-02-202-1012
【知 识 点】 数据库-JDBC、PLSQL-存储过程
【难易程度】 20
【题目描述】
用于调用存储过程的对象是。
【选项】
A.ResultSet B.DriverManager C.CallableStatemet D.PreparedStatement
【正确答案】 C
【解释】
ResultSet 是结果集对象;DriverManager 管理一组驱动程序;PreparedStatement 预编译的,用来发送和执行 SQL 语句的。

【题目编号】 jsd-02-202-2001
【知 识 点】 数据库-PLSQL-变量声明与赋值
【难易程度】 40
【题目描述】
在 PL/SQL 中使用哪几种语句来对变量进行赋值?
【选项】
A. := B. SELECT INTO C. FETCH INTO D. =
【正确答案】 ABC
【解释】无

【题目编号】 jsd-02-202-2002
【知 识 点】 数据库-PLSQL-自定义函数
【难易程度】 60
【题目描述】
下列说法正确的是( )
【选项】
A. 在PLSQL自定义函数中如果包含UPDATE、DELETE、INSERT语句,不必在函数体内给出COMMIT;
B. 自定义函数可以在SQL语句中调用、也可以在PLSQL块中调用
C. 自定义函数可以返回表类型
D. 自定义函数中的参数可以是OUT类型
【正确答案】 ABCD
【解释】无

【题目编号】 jsd-02-202-2003
【知 识 点】 数据库-PLSQL-变量的声明与赋值
【难易程度】 50
【题目描述】
考虑下列声明,那些是不合法的:
【选项】
A. DECLARE v_name, v_dept VARCHAR2(14);
B. DECLARE v_test NUMBER(5);
C. DECLARE V_MAXSALARY NUMBER(7, 2) = 5000;
D. DECLARE V_JOINDATE BOOLEAN := SYSDATE;
【正确答案】 ACD
【解释】
A.v_name 没有数据类型
C.:=是赋值
D.V_JOINDATE 是 boolean 类型,sysdate 是 Date 类型

【题目编号】 jsd-02-202-4001
【知 识 点】 数据库-PLSQL-程序结构
【难易程度】 60
【题目描述】
解释 TABLE Function 的用途
【正确答案】
TABLE Function 是通过 PL/SQL 逻辑返回一组纪录,用于普通的表/视图。他们也用于pipeline和 ETL(ETL,Extraction-Transformation-Loading 的缩写,中文名称为数据提取、转换和加载)过程。
【解释】无

【题目编号】 jsd-01-202-4002
【知 识 点】 数据库-PLSQL-程序结构
【难易程度】 70
【题目描述】
创建过程语法
CREATE [OR REPLACE] PROCEDURE Procedure_name
[ (argment [ { IN | IN OUT }] Type,
argment [ { IN | OUT | IN OUT } ] Type ]
{ IS | AS }
<类型.变量的说明>
BEGIN
<执行部分>
EXCEPTION
<可选的异常错误处理程序>
END;
请问,IN、OUT、IN OUT分别表示什么。
【正确答案】
【解释】无

  1. IN: 表示该参数不能被赋值(只能位于等号右边);
  2. OUT:表示该参数只能被赋值(只能位于等号左边);
  3. IN OUT: 表示该类型既能被赋值也能传值;

【题目编号】 jsd-01-202-4003
【知 识 点】 数据库-PLSQL-存储过程
【难易程度】 80
【题目描述】
如何调用存储过程
【正确答案】
存储过程建立完成后,只要通过授权,用户就可以在SQLPLUS 、ORACLE开发工具或第三方开发工具中来调用运行。
ORACLE 使用EXECUTE 语句来实现对存储过程的调用:
EXEC[UTE] Procedure_name( parameter1, parameter2…);
【解释】无

【题目编号】 jsd-01-202-4004
【知 识 点】 数据库-PLSQL-程序流程控制
【难易程度】 90
【题目描述】
plSql循环遍历的几种方式?
【正确答案】
1).loop循环
declare
v_i number;
begin
v_i:=1;
loop
v_i:=v_i+1;
if v_i=10 then exit; --退出循环还可以 exit when v_i=10;
end if;
end loop;
dbms_output.put_line(v_i);
end;
2).while循环
Declare
v_i number;
v_sum number;
begin
v_i:=1;v_sum:=0;
while v_i<=10 loop
v_i:=v_i+1;
v_sum:=v_i+v_sum;
end loop;
dbms_output.put_line(v_sum);
end;
3).for循环
declare
v_sum number:=0;
begin
for v_i in 1…10 loop
v_sum:=v_i+v_sum;
end loop;
dbms_output.put_line(v_sum);
end;
【解释】无

【题目编号】 jsd-01-202-4005
【知 识 点】 数据库-PLSQL-基本概念
【难易程度】 40
【题目描述】
plsql有什么用?
【正确答案】
plsql主要用来写存储过程的,它包含了SQL语句没有的那些逻辑的语句,像if end,while…之类的,可以实现更强大的功能。在某些情况下,比如说现在我要给某个表插入10000行的测试数据(有规律),写1000个insert 语句太麻烦,就用plsql实现。
【解释】无

【题目编号】 jsd-01-202-4006
【知 识 点】 数据库-PLSQL-序列
【难易程度】 60
【题目描述】
怎么用plsql创建序列
【正确答案】
create sequence 序列名 increment by 其实位置 start with 每次增加
Nomaxvalue nocycle
【解释】无

【题目编号】 jsd-01-202-4007
【知 识 点】 数据库-PLSQL-存储过程、自定义函数
【难易程度】 80
【题目描述】
存储过程和函数的区别
【正确答案】
从参数的返回情况来看:
如果返回多个参数值最好使用存储过程,如果只有一个返回值的话可以使用函数。 从调用情况来看:如果在 SQL 语句(DML 或 SELECT)中调用的话一定是存储函数或存储的封装函数不可以是存储过程, 但调用存储函数的时候还有好多限制以及函数的纯度等级的问题,如果是在过程化语句中调用的话, 就要看你要实现什么样的功能。函数一般情况下是用来计算并返回一个计算结果而存储过程一般是用来完成特定的数据操作(比如修改、插入数据库表或执行某些 DDL 语句等等),所以虽然他们的语法 上很相似但用户在使用他们的时候所需要完成的功能大部分情况下是不同的。
【解释】无

【题目编号】 jsd-01-202-4008
【知 识 点】 数据库-PLSQL-基本命令
【难易程度】 60
【题目描述】
你刚刚编译了一个 PL/SQL Package 但是有错误报道,如何显示出错信息?
【正确答案】
SHOW ERRORS
【解释】无

【题目编号】 jsd-02-202-5001
【知 识 点】 数据库-PLSQL-程序块编写、程序流程控制-条件结构
【难易程度】 50
【题目描述】
写出一个匿名的 SQL 程序块,完成如下任务:向表中插入 3000 条记录,在 salary 字段中有 500条记录的值为 1000,500 条记录的值为 1200,1000 条记录的值为 1500,1000 条记录的值为 1800,Id 字段的值来自序列 xl,其他字段的值任意。
【正确答案】
declare
x number:=0;
begin
for x in 1…3000 loop
If(x<=500) then
Insert into system.test values(x1.nextval,‘jim’,24,‘m’,1000);
elsif((x>500)and (x<1001)) then
Insert into system.test values(system.xl1.nextval,‘jim’,24,‘m’,1200);
elsif((x>1000)and (x<2001)) then
Insert into system.test values(system.xl1.nextval,‘jim’,24,‘m’,1500); Else
Insert into system.test values(system.xl1.nextval,‘jim’,24,‘m’,1800);
end if; end loop;
end;
【解释】无

【题目编号】 jsd-02-202-5002
【知 识 点】 数据库-PLSQL-存储过程
【难易程度】 30
【题目描述】
写出一个存储过程,这个存储过程的作用是修改特定 id 编号的记录,将该条记录的 salary 字 段的值加上 500;
【正确答案】
Create or replace procedure system.update_age
(vid in number) is
Begin
Update table1 set salary=salary+500 where id=vid;
End;
【解释】无

【题目编号】 jsd-02-202-5003
【知 识 点】 数据库-PLSQL-自定义函数
【难易程度】 50
【题目描述】
创建一个 system 方案中的函数 fn1,函数作用为:将指定 ID 号的记录中的 salary 字段值乘以1.05。
【正确答案】

Create or replace function
system.fn1(salary1 system.table1 salary &type)
Return number as
V1 numbre:=1.05; V2 numbre;
Begin
V2=v1*salary1; Return v2;
End ;
【解释】无

【题目编号】 jsd-02-202-5004
【知 识 点】 数据库-PLSQL-存储过程
【难易程度】 70
【题目描述】
假设有以下的两个表:
Cus_A
ID* Name Address
? ? ?
Cus_B
ID* Name Address
? ? ?
*主键
表 Cus_A 和表 Cus_B 的结构完全相同,表 Cus_A 和表 Cus_B 中既存在 ID 相同的记录,也存在 ID 不 同的记录。现要求将 ID 只存在于表表 Cus_A 中而不存在于表 Cus_B 中的记录全部插入到 Cus_B 表中, 并用表 Cus_A 中的记录更新 Cus_B 中相同的 ID 的记录,请写出完成这一功能的存储过程。
【正确答案】
create or replace procedure test is
cust_record cus_a%rowtype ;
cursor cust_cursor is select id,name,address from cus_a;
Begin
Open cust_cursor; LOOP
Fetch cust_cursor into cust_record; EXIT WHEN cust_cursor %NOTFOUND;
–先删除在插入
delete from cus_b where id=cust_record.id;
insert into cus_b values(cust_record.id, cust_record.name, cust_record.address); END LOOP;
end;
【解释】无

【题目编号】 jsd-02-202-5005
【知 识 点】 数据库-PLSQL- 程序流程控制
【难易程度】 60
【题目描述】
请用数据库语言求1-100之间的素数
【正确答案】
set serverout on
create or replace procedure is_prime(inp number)
as
i number;
j number;
is_prim boolean;
begin
dbms_output.new_line;
dbms_output.put(to_char(2)||’ ‘);
for i in 3…inp loop
begin
is_prim:=true;
for j in 2…trunc(sqrt(i)) loop
if mod(i,j)=0 then
begin
is_prim:=false;
exit;
end;
end if;
end loop;
if is_prim then dbms_output.put(to_char(i)||’ '); end if;
end;
end loop;
dbms_output.new_line;
end;
【解释】无

【题目编号】 jsd-02-202-5006
【知 识 点】 数据库-PLSQL-自定义函数
【难易程度】 70
【题目描述】
完成以下PL/SQL块,功能是:创建一个函数dept_name,其功能是接受职员编号后返回职员所在部门名称。(注:部门名称在dept表中,而职员信息在emp表中,职员所在部门号的列名为deptno)
【正确答案】
CREATE OR REPLACE FUNCTION dept_name (emp_no NUMBER)
RETURN VARCHAR2 AS
dept_no NUMBER(2);
result dept.dname%TYPE;
BEGIN
SELECT deptno INTO dept_no FROM emp WHERE empno=emp_no___
SELECT dname
INTO result FROM dept
WHERE deptno = dept_no;
RETURN result_;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END
【解释】无

【题目编号】 jsd-02-202-5007
【知 识 点】 数据库-PLSQL-程序流程控制-循环结构、条件结构
【难易程度】 60
【题目描述】
对所有员工,如果该员工职位是MANAGER,并且在DALLAS工作那么就给他薪金加15%;如果该员工职位是CLERK,并且在NEW YORK工作那么就给他薪金扣除5%;其他情况不作处理
【正确答案】
declare cursor c1 is select * from emp;
c1rec c1%rowtype;
v_loc varchar2(20);
begin
for c1rec in c1 loop
select loc into v_loc from dept where deptno = c1rec.deptno;
if c1rec.job = ‘MANAGER’ and v_loc = ‘DALLAS’ then
update emp set sal = sal * 1.15 where empno = c1rec.empno;
elsif c1rec.job=‘CLERK’ and v_loc = ‘NEW YORK’ then
update emp set sal = sal * 0.95 where empno = c1rec.empno;
else null;
end if;
end loop;
end;
【解释】无

【题目编号】 jsd-02-202-5008
【知 识 点】 数据库-PLSQL-程序流程控制、游标
【难易程度】 50
【题目描述】
对直接上级是’BLAKE’的所有员工,按照参加工作的时间加薪:
81年6月以前的加薪10% ;81年6月以后的加薪5%
【正确答案】
declare cursor c1 is select * from emp where mgr = (select
empno from emp where ename=‘BLAKE’); --直接上级是’BLAKE’的所有员工
c1rec c1%rowtype;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值