欢迎来到天天文库
浏览记录
ID:62154192
大小:36.50 KB
页数:4页
时间:2021-04-19
《实验二PLSQL编程实验报告.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、个人收集整理勿做商业用途课程名称:ORACLE数据库系统及应用 成绩评定: 湖南第一师范学院信息科学与工程系实验报告实验项目名称:实验二:PL/SQL编程 指导教师: 学生姓名: 学号: 专业班级: 实验项目类型: 设计 实验地点: 实验时间: 年月日一、实验目的与要求:1、掌握 PL/SQL程序设计的基本知识; 2、掌握PL/SQL 中SELECT语句和 DML 语句的正确使用方法;3、掌握存储过程、函数、游标、触发器与包的创建与使用。二、实验环境:(硬件环境、软件环境)1.硬件环境:奔ⅣP
2、C。2.软件环境:Windows2000操作系统,Oracle9i。三、实验内容:(原理、操作步骤、程序代码等)任务:1、编写存储过程,根据用户输入的部门编号实现在PL/SQL 中逐行显示emp 表中该部门员工的工资级别。工资级别是:当工资为空时,为空,工资在1000元以下的为‘低’,在1000和3000之间的为‘中’,高于3000元的为‘高’。要有异常处理(该部门编号不存在)。createor replaceprocedure review_ep(v_deptnoindept.deptno%type)iscursorc1isselect *
3、 from emp whereemp.deptno=v_deptno;record1emp%rowtype;deptno_not_foundexception;beginopen c1;fetchc1intorecord1;if(not c1%found)thenraise deptno_not_found;end if;whilec1%found loopifnvl(record1.sal,0)<1000 thendbms_output.put_line(record1.ename
4、
5、'工资低');elsifnvl(record1.sal,
6、0)<3000thendbms_output.put_line(record1.ename
7、
8、'工资中等');elsedbms_output.put_line(record1.ename
9、|'工资高');endif;fetch c1into record1;个人收集整理勿做商业用途endloop;closec1;exceptionwhendeptno_not_found thendbms_output.put_line('deptno notfound');end;2.有这么一张表temp1,他只有一个 number(8)的字段no,由于在创
10、建表时忘记设置主键约束,导致表中有很多重复的记录。请你编写一个存储过程,将表中重复的记录保留一个,删除其余的。createorreplaceproceduremypro1iscursorv_cursorisselect distinct* fromtemp1;f_notemp1.no%type;begin openv_cursor; fetchv_cursor intof_no; deletefrom temp1;whilev_cursor%found loop insertintotemp1values(f_no); f
11、etch v_cursorintof_no; endloop; closev_cursor;end;3.编写一个存储函数,用于判断DEPT 表中某一编号的部门是否存在,若存在此部门编号,则返回 TRUE,否则返回FALSE。Create orreplacefunctionjudge_dept(v_deptnodept.deptno%type)return booleanisv_deptno2dept.deptno%type:=-1;beginselectdeptnointo v_deptno2fromdept wheredeptno=v
12、_deptno;if(v_deptno2<>-1)thenreturntrue;elsereturn false;end if;end;4、编写一过程,调用第3题的函数判断某一编号的部门是否存在,存在则输出该部门员工的姓名、工作,否则提示不存在此部门或此部门无员工。 createorreplaceproceduredno(v_deptnodept.deptno%type)iscursorc1is select*fromempwhere deptno=v_deptno;record2emp%rowtype;v_judgeboolean:=fal
13、se;beginv_judge:=judge_dept(v_deptno);if(v_judge)then个人收集整理勿做商业用途openc1;fetch c1in
此文档下载收益归作者所有