Oracle_PLSQL测试题与答案(绝对经典)
- 格式:doc
- 大小:47.00 KB
- 文档页数:5
Oracle PL/SQL测试题
姓名:___ _________
一、选择题
1、Oracle数据库中为新创建的表分配的初始空间通常为多大(B)
A、一个块
B、一个区
C、一个段
D、c一个表空间
2、关于存储过程参数,正确的说法是(B)
A、存储过程的输出参数可以是标量类型,也可以是表类型
B、存储过程输入参数可以不输入信息而调用过程
C、可以指定字符参数的字符长度(函数的()或者过程的(number/varchar2))
D、以上说法都不对
3、下列说法,正确的说法是(B)
A、只要在存储过程中有增删改语句,一定加自治事务
B、在函数内可以修改表数据
C、函数不能递归调用
D、以上说法都不对
4、有一产品表(编号,名称,价格,数量,所属分类),下列语法不正确的是(D)
A、select * from 产品表 where价格>1000
B、select sum(价格) from 产品表 group by 所属分类 having max(价格)>1000
C、select所属分类,sum(价格) from 产品表 where 价格>1000 group by 所属分类
D、select所属分类,sum(价格) from 产品表 where max(价格)>1000 group by 所属分类
5、关于触发器,下列说法正确的是(B)
A、可以在表上创建INSTEAD OF 触发器
B、语句级触发器不能使用“:old”和“:new”
C、行级触发器不能用于审计功能
D、触发器可以显式调用
6、下列那些是Oracle的伪列(ACD)
A、ROWID
B、ROW_NUMBER()
C、LEVEL
D、ROWNUM
E、COLUMN
7、当表的重复行数据很多时,应该创建的索引类型应该是( C ) A、B树
B、reverse
C、bitmap
D、函数索引
8、在建表时如果希望某列的值,在一定的范围内,应建什么样的约束?(C )
A、primary key
B、unique
C、check
D、not null
9、利用游标来修改数据时,所用的。。FOR UPDATE充分利用了事务的哪个特性?( D)
A、原子性
B、一致性
C、永久性
D、隔离性
10、下列说法不正确的是()全对
A、在PLSQL自定义函数中如果包含UPDATE、DELETE、INSERT语句,不必在函数体内给出COMMIT;
B、自定义函数可以在SQL语句中调用、也可以在PLSQL块中调用
C、自定义函数可以返回表类型
D、自定义函数中的参数可以是OUT类型
二、编程题
1、查找出当前用户模式下,每张表的记录数,以scott用户为例,结果应如下:
DEPT...................................4
EMP...................................14
BONUS.................................0
SALGRADE.............................5
其实现的代码是:
declare
type tab_names is table of varchar2(20) index by binary_integer;
tab_name tab_names;
coun number;
str varchar2(100);
begin
select table_name bulk collect into tab_name from user_tables;
for i in tab_name.first..tab_st loop
str:='select count(*) from '||tab_name(i);
execute immediate str into coun;
dbms_output.put_line(tab_name(i)||'..........'||coun);
end loop;
end;
2、某cc表数据如下:
c1 c2
--------------
1 西
1 安
1 的
2 天
2 气
3 好
……
转换为
1 西安的
2 天气
3 好
要求:不能改变表结构及数据内容,仅在最后通过SELECT显示出这个查询结果
代码为:
create or replace function x return
varchar2
is
type t_array is table of number index by binary_integer;
type tarray is table of varchar2(10) index by binary_integer;
ta t_array;
tar tarray;
re varchar2(10);
n number;
na varchar2(10);
begin
select id bulk collect into ta from (select id,name from xx order by id) group by id;
for i in st loop
dbms_output.put(ta(i)||' ');
select name bulk collect into tar from xx where id=ta(i);
for i in st loop
dbms_output.put(tar(i));
end loop;
dbms_output.put_line(' '); end loop;
return re;
end;
2、请用一条sql语句查询出scott.emp表中每个部门工资前三位的数据,显示结果如下:
DEPTNO SAL1 SAL2 SAL3
------ ---------- ---------- -------------------------------------
10 5000 2450 1300
20 3000 2975 1100
30 2850 1600 1500
则,该语句为:
select deptno,max(sal) sal1,max(decode(t,2,sal)) sal2,min(sal ) sal3
from (select sal,deptno,t from
(select empno,ename,sal,row_number() over(partition by deptno order by sal desc)
t,deptno from emp ) e where e.t<=3) group by deptno
3、表nba记录了nba(team VARCHAR2(10),y NUMBER(4))夺冠球队的名称及年份:
TEAM Y -------------------- ------------------------------
活塞 1990
公牛 1991
公牛 1992
公牛 1993
火箭 1994
火箭 1995
公牛 1996
公牛 1997
公牛 1998
马刺 1999
湖人 2000
湖人 2001
湖人 2002
马刺 2003
活塞 2004
马刺 2005
热火 2006
马刺 2007
凯尔特人 2008
湖人 2009
湖人 2010
请写出一条SQL语句,查询出在此期间连续获得冠军的有哪些,其连续的年份的起止时间是多少,结果如下:
TEAM B E
-------------------- ---------- --------------------------------
公牛 1991 1993
火箭 1994 1995
公牛 1996 1998
湖人 2000 2002
湖人 2009 2010
select max(nn.team) team,min(nn.y) B,max(nn.y)+1 E from
(select n2.team,n2.y from (select * from nba) n1 join
(select * from nba) n2
on n1.team=n2.team
where n1.y=n2.y+1) nn
group by (nn.y-rownum)
order by B