plsql测试参考答案.docx
- 文档编号:4658192
- 上传时间:2022-12-07
- 格式:DOCX
- 页数:6
- 大小:23.26KB
plsql测试参考答案.docx
《plsql测试参考答案.docx》由会员分享,可在线阅读,更多相关《plsql测试参考答案.docx(6页珍藏版)》请在冰豆网上搜索。
plsql测试参考答案
J创建一个emp1表,其结构和数据与emp表完全一致。
用游标完成操作:
显示工资低于1500的职员信息,并显示如果给他们涨30%工资后的工资。
createtableemp1asseIect*fromemp;
setserveroutputon
declare
cursorcurisselect*fromempwheresal<1500;
begin
forv_counterincurloop
ii…iiii…iiiliiir・iiir・iiii・*n*;
endloop;
end;
2、编写一个pl/sql块,输出所有员工的员工名、员工号、工资和部门号。
declare
cursorc_empisselect*fromemp;
begin
forv_empinc_emploop
ii"mi1JiirJi;
endloop;
end;
3、查询名为“smith”的员工信息,并输出其员工号、工资、部门号。
如果该员工不存在,则插入一条新记录,员工号为2007,员工名为“smith”,工资为1500,部门号为10。
如果存在多个名为"smith"的员工,则输出所有名为"smith"的员工号、工资和部门号。
DecIarev_empemp%rowtype;
begin
seIect*intov_empfromempwhereename=fsmith1;
II"Illi''ll;
exception
whenno_data_foundthen
insertintoemp(empno,ename,saI,deptno)
vaIues(2007,'smith1,1500,10);
whentoo_many_rowsthen
forvin(seIect♦fromempwhereename=lsmith')loop
IPTill''ll;
endloop;
end;
4、创建一个存储过程,以员工号为参数,输出该员工的工资。
createorreplaceprocedureshowsal(p_empno%type)asv_sal%type;
begin
seIectsalintov_salfromempwhereempno=p_empno;
(v_saI);
begin
showsaI(7844);
end;
5、创建一个函数,以部门号为参数,返回该部门的平均工资;
createorrepIacefunctionfun_avgsal(p_deptno%type)return%type
asv_sal%type;
begin
seIectavg(sal)intov_salfromempwhere
deptno=p_deptno;
returnv_saI;
begin
(fun_avgsaI(10));
end;
6、创建一个函数,以员工号为参数,返回该员工所在部门的平均工资。
createorreplacefunctionfun_saI(p_empno%type)return%type
asv_sal%type;
begin
seIectavg(sal)intov_salfromempwheredeptno二
(seIectdeptnofromempwhereempno=p_empno);
returnv_saI;
begin
(fun_saI(7844));
end;
7、在e叩表上创建一个触发器,当插入、删除或修改员工信息时,统计各个部门的人数及平均工资,并输出。
createorrepIacetriggertrg_empafterinsertorupdateordeleteonemp
declare
v_salype;
v_countnumber;
begin
seIectavg(sal),count(*)intov_saI,v_countfromemp;
(v_saI||1'llv_count);
end;
updateempsetsaI=500whereempno=7844;
8、创建一个包,包含一个过程和一个游标。
游标返回所有员工的信息,过程实现每次输出游标中的5条记录。
createorreplacepackagepkg_persistcursoras
cursorc_empisselect*fromemp;
proceduredisplayemp;
end;
createorreplacepackagebodypkg_persistcursor
Asproceduredisplayemp
Asv_empemp%rowtype;
ifnotc_emp%isopenthen
openc_emp;
foriin1..5loopfetchc_empintov_emp;
irmi;
endIoop;
end;//
begin
end;
9、创建一个存储过程,以2个整数为参数,输出工资在两者间
的员工信息。
createorreplaceprocedurebinary_integer,maxbinary_integer)as
begin
forv_empin(seIect*fromemp
minandmax)loop
ir’llir’llii…iiir‘丨丨
•ii;
endloop;
end;
saIbetween(min
wheresalbetween
-iiirJiir
saIbetween(1000,3000);
end;
10.在emp表上创建一个級发器,保证修改员工工资时,改后的工资低于同部门的最高工资,同时高于同部门的最低工资。
createorrepIacepackagepkg_deptno
asv_deptno%type;
v_sal%type;
end;//
createorrepIacetriggertrg_updateemp
beforeupdateonemp
foreachrow
end;//createorreplacetriggertrg_statement
afterupdateonemp
declare
v_highsaI%type;
v_lowsal%type;
begin
seIectmax(saD^minCsal)intov_highsaI,v_IowsaIfromempwheredeptno=;
if>v_highsaIor raise_application_error(-20001,'thesalisbeyond! r); endif; updateempsetsaI=500whereempno=7844; 11.在emp表上创建一个触发器,当插入、删除或修改员工信息时,统计各个部门的人数及平均工资并输出。 12、创建一个包,包含一个过程和一个函数。 过程以部门号为参数输出该部门中工资最高的员工名和员工号,函数以部门号为参数返回该部门员工的最高工资。 createorrepIacepackagepkg_emp as functionfunc_highsal(p_deptno%type)return%type; procedureproc_highsal(p_deptno%type); end;// createorreplacepackagebodypkg_emp asfunctionfunc_highsaI(p_deptno%type) return%type asv_highsaI%type; begin seIectmax(saI)intov_highsaIfromempwheredeptno=p_deptno; returnv_highsaI; end; procedureproc_highsal(p_deptno%type) as begin forv_empin(seIect*fromempwheredeptno=p_deptno andsaI=func_highsaI(p_deptno))loop irji; endloop; end; end;// begin end;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- plsql 测试 参考答案
![提示](https://static.bdocx.com/images/bang_tan.gif)