数据库上机-实验3.doc_第1页
数据库上机-实验3.doc_第2页
数据库上机-实验3.doc_第3页
数据库上机-实验3.doc_第4页
数据库上机-实验3.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验三 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是工资等级表,包括:工资等级、最低工资、最高工资三个属性,即SALGRADE(GRADE,LOSAL,HISAL)。1 编写一个函数来找出职工工资数额的信息,该函数还可以接受职工的号码。 create or replace procedure get_sal(id_param in scott.emp.empno%type,sal_param out scott.emp.sal%type)isbegin select sal into sal_param from scott.emp where empno=id_param;end get_sal; /测试 set serverout ondeclare sal scott.emp.sal%type;begin get_sal(7369,sal); dbms_output.put_line(sal);end;2 编写一个函数来找出职工的经理信息,该函数还可以接受职工的姓名。 create or replace procedure get_mgr(id_param in scott.emp.empno%type,mgr_param out scott.emp.mgr%type)isbegin select mgr into mgr_param from scott.emp where empno=id_param;end get_mgr; /测试 set serverout ondeclare mgr scott.emp.mgr%type;begin get_mgr(7369,mgr); dbms_output.put_line(mgr);end;3 编写一个函数,该函数可以根据接受职工的号码。来返回ENAME、SAL、DEPTNO信息。 create or replace procedure get_emp_basicInf(empno_param in scott.emp.empno%type,empname_param out scott.emp.ename%type,sal_param out scott.emp.sal%type,deptno_param out scott.emp.deptno%type) isbegin select ename,sal,deptno into empname_param,sal_param,deptno_param from scott.emp where empno=empno_param;end get_emp_basicInf;/测试 set serverout ondeclare empno_param number:=7369; ename_param scott.emp.ename%type; sal_param scott.emp.sal%type; deptno_param scott.emp.deptno%type;begin get_emp_basicInf(empno_param,ename_param,sal_param,deptno_param); dbms_output.put_line(empno:|empno_param| ename:|ename_param| sal:|sal_param| deptno:|deptno_param);end;4 编写一个函数,该函数可以根据接受的职工姓名,来确定该职工的年收入信息。如果有两个或以上重名职工的话将出现错误信息。 create or replace function get_yearlySal(ename_param scott.emp.ename%type) return number is comm_param number; sal_param number; yearlySal number;begin select comm,sal into comm_param,sal_param from scott.emp where ename=ename_param; if comm_param=null then comm_param:=0; end if; if sql%notfound then yearlySal:=-1; else yearlySal:=12*(comm_param+sal_param); end if; return(yearlySal);end get_yearlySal;set serverout ondeclare ename scott.emp.ename%type:=WARD; yearlySal number;begin yearlySal:= get_yearlySal(ename); dbms_output.put_line(nianx|yearlySal);end;5 编写一个存储过程来显示出DEPT表的所有信息。6 编写一个存储过程来显示出EMP表信息,而且该过程可以接受DEPTNO列的数据。7 根据工作类别,编写一个存储过程来找出工资数额最高的职工信息。8 编写一个包,它包括一个能显示职工信息的过程,以及一个可以自动生成主关键字的函数。9 编写一个触发器,它能够自动计算所有职

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论