


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验项目类型: 设计 实验地点:课程名称:ORACLE据库系统及应用成绩评定:湖南第一师范学院信息科学与工程系实验报告实验项目名称:实验二:PL/SQL编程指导教师:学生姓名:学号:专业班级:实验时间:年 月曰一、实验目的与要求:1、掌握PL/SQL程序设计的基本知识;2、掌握PL/SQL中SELECT语句和 DML语句的正确使用方法;3、掌握存储过程、函数、游标、触发器与包的创建与使用。二、实验环境:(硬件环境、软件环境)1?硬件环境:奔W pc。2. 软件环境: Windows2000 操作系统,Oracle 9i。三、实验内容:(原理、操作步骤、程序代码等)任务:1、编写存储过程,根据用
2、户输入的部门编号实现在PL/SQL中逐行显示emp表中该部门员工的工资级别。工资级别是:当工资为空时,为空,工资在1000元以下的为低,在 1000和3000之间的为中,高于3000元的为高。要有异常处理(该部门编号不存在)。create or replaceprocedure review(v dept noin dept.dept no%type ) iscursor c1 is select * fromempwhere emp.dept no 二v dept no ;record1 emp%rowtype ;dept no no t fou ndexcepti on ;beg in o
3、pe n c1 ;fetchc1 intorecord1 :if ( notc1 %fou nd)the nraisedept no_no t_fou ndend ifwhilec1 %fou ndloopif n vl (record1.sal , 0) 1000 thendbms output.put line(record1.e nameII工资低;elsifnvl (record1.saldbms output.put lineelse,0) 3000 then(record1.e nameII工资中等;dbms output.put li ne(record1.e nameII工资高
4、;end if :fetch c1 into record1 end loop : close cl :the nexcepti on whe n dept no_no t_fou nddbms output.put li ne(dept no not found);end ;2.有这么一张表tempi ,他只有一个number(8)的字段no,由于在创建表时忘记设置主键约束,导致表中有很多重复的记录。请你编写一个存储过程,将表中重复的记录保留一个,删除其余的。create or replace procedure myprol iscursor v_cursor is select dist
5、i net * from tempi; f_no tempi. no %type;begi nope n v_cursor;fetch v_cursor into f_no;delete from tempi ;while v_cursor%fo und loopin sert into tempi values(f_ no); fetch v_cursor into f_no;end loop;close v_cursor;en d;3. 编写一个存储函数,用于判断DEPT表中某一编号的部门是否存在,若存在此部门编号,则返回TRUE,否则返回 FALSECreate or replace f
6、un cti on judge_dept ( v_dept no dept.dept no %type) return boolea nisv dept no2 dept.dept no %type:二-i ;beg inselect dept no into v dept no2 from dept wheredept no 二v dept no ;if ( v_dept no 2-i) the nreturn true;|else returnfalse;end if;end ;4、编写一过程,调用第3题的函数判断某一编号的部门是否存在,存在则输出该部门员工的姓名、工作,否则提示不存在此部
7、门或此部门无员工。create or replace procedure dno (v_dept nodept.dept no%type ) iscursor ci is select * from emp wheredept no =v_dept no ;record2emp%rowtype ;v judgeboolea n :二 falsebeg inv judge:二iudge_dept( v_dept no );if (v_judge ) the nope n cl ;fetchcl into record2 ;whilecl %ound loopdbms output.put li
8、ne(record2.e nameII| record2.job);fetchc1 into record2 ;endloop ;closec1 ;elsedbms output.put li ne(dept no not found);endend ;if ;5、编写一个触发器,在DEPT表执行INSERT语句后被激发,此触发器将新部门的编号(dept no)、名称(dn ame) 及执行此操作的用户(USER)、当时的日期(SY SDAT日插入N_DEPT表(注:此 表已建好,表结构为N_DEPT ( DEPTNO NUMBER(4),DNAME VARCHAR2(10), UNAMEVA
9、RCHAR2(20),INDATE DATE)。create table n dept(dept no n umber(4),d n ame varchar2(10), un ame varchar2(20),i n date date);create or replace trigger del empafter in sert on deptfor each rowbeg inin sert into n dept values(: new.dept no,: new.d name,user,sysdate); en d;in sert into dept values(60,MMMM,h
10、u nan);6、 创建触发器CHECK_SAL,禁示对职务为 CLERK的雇员的工资修改值超出1000至2000的范围,即CLERK职务员工的修改后工资值只能在10002000之间。要求测试该触发器。create or replacetrigger update_empafter update on empfor each rowbeg inif (: n ew.saln ot betwee n 1000 and 2000 and : old.job二CLERK ) the nrollback ;end if ;end ;7、 编写一个管理雇员信息的包emp_manapack。包中有过程或函
11、数如下:1) 通过员工编号计算出员工应交个人所得税款2) 通过员工编号插入员工3) 通过员工编号删除员工4) 按工资升序输出所有雇员的应交所得税清单create or replacepackage emp ma n isrecord2 emp%rowtype ;fun cti on pers ( v_noemp.emp no %type)returnnu mber ;procedure cou nts end emp_ma n ;createor replacepackage body emp ma n isn umber isfun cti onpers ( v_noemp.emp no %type ) retur nv salnu mber := 0;beg inend ;procedure cou nts iscursor cursor2 is select * from emp ;record3 emp%rowtype ;v sal2nu mber := 0;beg inope n cursor2 ;fetch cursor2 into recor
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 营养与骨骼健康促进考核试卷
- 农药生产过程有害生物防治技术考核试卷
- 保护大自然的演讲稿
- 企业半年工作总结(集合14篇)
- 个人周工作总结3篇
- 河南省重大活动方案
- 正月初六回娘家活动方案
- 正月店铺活动策划方案
- 水果相关活动方案
- 汽车集团活动方案
- 校长在2025暑假前期末教师大会上的讲话:静水深流脚踏实地
- 肿瘤护理专家共识
- 应急广播施工管理制度
- 2025春季学期国开电大本科《理工英语3》一平台在线形考综合测试(形考任务)试题及答案
- 三一挖机合同协议书
- 我国生命教育二十年的发展回顾与未来展望
- 2025年微生物学基础与应用试题及答案
- 型录制作的基本要求试题及答案
- 空气能维保合同协议
- 前厅主管考试试题及答案
- 市政道路交通导改方案
评论
0/150
提交评论