欢迎来到天天文库
浏览记录
ID:38371427
大小:36.00 KB
页数:5页
时间:2019-06-11
《数据库上机-实验3》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验三PL/SQL编程(2)目的和要求:1.掌握存储过程和函数的使用2.掌握游标的使用3.掌握程序包的使用4.掌握触发器的使用实验内容:SCOTT用户拥有DEPT、EMP、SALGRADE表对象,其中,DEPT是部门信息表,包括:部门编号、部门名称、部门地址三个属性,即DEPT(DEPTNO,DNAME,LOC)。EMP是员工信息表,包括:员工编号、员工姓名、职位、上级领导、雇用时间、薪金、佣金、所属部门编号八个属性,即EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)。SALGRADE是工资等级表,包括:工资等级、最低工资、最高
2、工资三个属性,即SALGRADE(GRADE,LOSAL,HISAL)。1.编写一个函数来找出职工工资数额的信息,该函数还可以接受职工的号码。createorreplaceprocedureget_sal(id_paraminscott.emp.empno%type,sal_paramoutscott.emp.sal%type)isbeginselectsalintosal_paramfromscott.empwhereempno=id_param;endget_sal;//测试setserveroutondeclaresalscott.emp.sal%type;beginge
3、t_sal('7369',sal);dbms_output.put_line(sal);end;1.编写一个函数来找出职工的经理信息,该函数还可以接受职工的姓名。createorreplaceprocedureget_mgr(id_paraminscott.emp.empno%type,mgr_paramoutscott.emp.mgr%type)isbeginselectmgrintomgr_paramfromscott.empwhereempno=id_param;endget_mgr;//测试setserveroutondeclaremgrscott.emp.mgr%ty
4、pe;beginget_mgr('7369',mgr);dbms_output.put_line(mgr);end;2.编写一个函数,该函数可以根据接受职工的号码。来返回ENAME、SAL、DEPTNO信息。createorreplaceprocedureget_emp_basicInf(empno_paraminscott.emp.empno%type,empname_paramoutscott.emp.ename%type,sal_paramoutscott.emp.sal%type,deptno_paramoutscott.emp.deptno%type)isbegins
5、electename,sal,deptnointoempname_param,sal_param,deptno_paramfromscott.empwhereempno=empno_param;endget_emp_basicInf;//测试setserveroutondeclareempno_paramnumber:=7369;ename_paramscott.emp.ename%type;sal_paramscott.emp.sal%type;deptno_paramscott.emp.deptno%type;beginget_emp_basicInf(empno_para
6、m,ename_param,sal_param,deptno_param);dbms_output.put_line('empno:'
7、
8、empno_param
9、
10、'ename:'
11、
12、ename_param
13、
14、'sal:'
15、
16、sal_param
17、
18、'deptno:'
19、
20、deptno_param);end;1.编写一个函数,该函数可以根据接受的职工姓名,来确定该职工的年收入信息。如果有两个或以上重名职工的话将出现错误信息。createorreplacefunctionget_yearlySal(ename_paramscott.emp.ename%type)returnnumbe
21、riscomm_paramnumber;sal_paramnumber;yearlySalnumber;beginselectcomm,salintocomm_param,sal_paramfromscott.empwhereename=ename_param;ifcomm_param=nullthencomm_param:=0;endif;ifsql%notfoundthenyearlySal:=-1;elseyearlySal:=12*(comm_param+sal_param);end
此文档下载收益归作者所有