欢迎来到天天文库
浏览记录
ID:14117148
大小:91.00 KB
页数:6页
时间:2018-07-26
《lab16_plsql程序设计》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、大型数据库实验报告学院:信息技术学院班级:软件一班专业:软件工程姓名:蔡泽鸿日期:2013-06-1820:35:00学号:10010300041.实验目的l掌握PL/SQL功能模块的应用l掌握存储过程、函数、包的创建l掌握存储过程、函数、包的维护2.实验内容(注意,实验代码和过程中产生的数据要上交,请同学们用spool命令记录下代码和过程)2.1.编写存储过程(使用scott用户的emp表)1.编写一个名称为P+姓名拼音简称+学号最后两位的存储过程,以员工号为参数,修改该员工的工资。若该员工属于10号部门,则工资增加150;若属于20号部门,则工资增加200;若属于30号部门,则工资增加2
2、50;若属于其他部门,则工资增加300.答:SQL>connscott/tigerConnected.SQL>selectdeptno,empno,salfromemp;createorreplaceprocedurep_czh04(v_empnoemp.empno%type)2as3v_deptnoemp.deptno%type;4v_salemp.sal%type;5begin6selectsal,deptnointov_sal,v_deptnofromemp7whereempno=v_empno;8ifv_deptno=10thenv_sal:=v_sal+150;9elsifv_de
3、ptno=20thenv_sal:=v_sal+200;10elsifv_deptno=30thenv_sal:=v_sal+250;11elsev_sal:=v_sal+300;12endif;13updateempsetsal=v_salwhereempno=v_empno;14*endp_czh04;3.编写一个匿名块调用此过程并验证所写的存储过程是否正确。答:declare2begin3p_czh04(7369);4end;5/selectdeptno,empno,salfromemp;1.1.编写存储过程(使用scott用户的emp表)1.编写一个名称为Proc+姓名拼音简称+学号
4、最后两位的存储过程,以部门号为参数,输出入职日期最早的10个员工信息.答:selectename,deptno,hiredatefromemp;setserveroutputon;createorreplaceprocedureproc_czh04(v_deptnoemp.deptno%type)2as3cursormycursoris4select*fromemp5whererownum<10anddeptno=v_deptnoorderbyhiredate;6begin7forv_czh04inmycursor8loop9dbms_output.put_line(v_czh04.enam
5、e
6、
7、''
8、
9、v_czh04.deptno
10、
11、''
12、
13、v_czh04.hiredate);10endloop;11*end;12/2.编写一个匿名块调用此过程并验证所写的存储过程是否正确。SQL>declare2begin3proc_czh04(20);4end;5/l编写存储过程(使用scott用户的emp表)1.创建一个名称为PMng+姓名拼音简称+学号最后两位的存储过程,以员工号为参数,返回该员工的领导姓名和工资。(注意是带返回参数的存储过程)答:createorreplaceprocedurepming_czh042(v_empnoemp.empno%type,3v_leaderou
14、temp.ename%type,4v_saloutemp.sal%type)5as6begin7dbms_output.put_line('员工姓名员工工资');8selecte2.ename,e2.salintov_leader,v_salfromempe1,empe29wheree1.empno=v_empnoande1.mgr=e2.empno;10dbms_output.put_line(v_leader
15、
16、''
17、
18、v_sal);11*endpming_czh04;12/1.编写一个匿名块调用此过程并验证所写的存储过程是否正确。declare2v_leaderemp.ename%ty
19、pe;3v_salemp.sal%type;4begin5pming_czh04(7369,v_leader,v_sal);6end;7/l创建函数(使用scott用户的emp表)1.创建一个名称为f+姓名拼音简称+学号最后两位的函数,以员工号为参数,返回该员工所在部门的平均工资、总工资、最高工资。答:createorreplacefunctionf_czh042(v_empnoemp.empno%type,
此文档下载收益归作者所有