实验二-PL-SQL编程实验报告

上传人:夏** 文档编号:571146306 上传时间:2024-08-08 格式:PDF 页数:6 大小:343.21KB
返回 下载 相关 举报
实验二-PL-SQL编程实验报告_第1页
第1页 / 共6页
实验二-PL-SQL编程实验报告_第2页
第2页 / 共6页
实验二-PL-SQL编程实验报告_第3页
第3页 / 共6页
实验二-PL-SQL编程实验报告_第4页
第4页 / 共6页
实验二-PL-SQL编程实验报告_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《实验二-PL-SQL编程实验报告》由会员分享,可在线阅读,更多相关《实验二-PL-SQL编程实验报告(6页珍藏版)》请在金锄头文库上搜索。

1、课程名称:ORACLE 数据库系统及应用 成绩评定: 实验项目名称: 实验二:PL/SQL 编程 指导教师: 学生姓名: 学号: 专业班级: 实验项目类型: 设计 实验地点: 实验时间: 年 月 日 一、实验目的与要求: 1、掌握 PL/SQL 程序设计的基本知识; 2、掌握 PL/SQL 中 SELECT 语句和 DML 语句的正确使用方法; 3、掌握存储过程、函数、游标、触发器与包的创建与使用。 二、实验环境: (硬件环境、软件环境) 1.硬件环境:奔 PC。 2.软件环境:Windows2000 操作系统,Oracle 9i。 三、实验内容: (原理、操作步骤、程序代码等) 任务: 1、

2、 编写存储过程,根据用户输入的部门编号实现在 PL/SQL 中逐行显示 emp 表中该部门员工的工资级别。工资级别是:当工资为空时,为空,工资在 1000 元以下的为低 ,在 1000 和 3000 之间的为中 ,高于 3000 元的为高 。要有异常处理(该部门编号不存在) 。 create or replace procedure review_ep (v_deptno in %type)is cursor c1 is select * from emp where =v_deptno; record1 emp%rowtype; deptno_not_found exception; beg

3、in open c1; fetch c1 into record1; 湖南第一师范学院信息科学与工程系实验报告 if(not c1%found) then raise deptno_not_found; end if; while c1%found loop if nvl,0)1000 then |工资低); elsif nvl,0)3000 then |工资中等); else |工资高); end if; fetch c1 into record1; end loop; close c1; exception when deptno_not_found then (deptno not fo

4、und); end; 2.有这么一张表 temp1,他只有一个 number(8)的字段 no,由于在创建表时忘记设置主键约束,导致表中有很多重复的记录。请你编写一个存储过程,将表中重复的记录保留一个,删除其余的。 create or replace procedure mypro1 is cursor v_cursor is select distinct * from temp1; f_no %type; begin open v_cursor; fetch v_cursor into f_no; delete from temp1 ; while v_cursor%found loop

5、insert into temp1 values(f_no); fetch v_cursor into f_no; end loop; close v_cursor; end; 3.编写一个存储函数,用于判断 DEPT 表中某一编号的部门是否存在,若存在此部门编号,则返回 TRUE,否则返回 FALSE。 Create or replace function judge_dept(v_deptno %type) return boolean is v_deptno2 %type:=-1; begin select deptno into v_deptno2 from dept where de

6、ptno=v_deptno; if(v_deptno2-1) then return true; else return false; end if; end; 4、 编写一过程, 调用第 3 题的函数判断某一编号的部门是否存在, 存在则输出该部门员工的姓名、工作,否则提示不存在此部门或此部门无员工。 create or replace procedure dno(v_deptno %type)is cursor c1 is select * from emp where deptno=v_deptno; record2 emp%rowtype; v_judge boolean:=false;

7、 begin v_judge:=judge_dept(v_deptno); if(v_judge) then open c1; fetch c1 into record2; while c1%found loop | |; fetch c1 into record2; end loop; close c1; else (deptno not found); end if; end; 5、编写一个触发器,在 DEPT 表执行 INSERT 语句后被激发,此触发器将新部门的编号(deptno)、名称(dname)及执行此操作的用户(USER) 、当时的日期(SYSDATE)插入 N_DEPT 表(

8、注:此表已 建 好 , 表 结 构 为 N_DEPT ( DEPTNO NUMBER(4),DNAME VARCHAR2(10), UNAME VARCHAR2(20),INDATE DATE) ) 。 create table n_dept(deptno number(4),dname varchar2(10), uname varchar2(20),indate date); create or replace trigger del_emp after insert on dept for each row begin insert into n_dept values(:,:,user

9、,sysdate); end; insert into dept values(60,MMMM,hunan); 6、创建触发器 CHECK_SAL,禁示对职务为 CLERK 的雇员的工资修改值超出 1000 至 2000 的范围,即 CLERK 职务员工的修改后工资值只能在 10002000 之间。要求测试该触发器。 create or replace trigger update_emp after update on emp for each row begin if(: not between 1000 and 2000 and :=CLERK)then rollback; end if

10、; end; 7、编写一个管理雇员信息的包 emp_manapack。包中有过程或函数如下: 1)通过员工编号计算出员工应交个人所得税款 2)通过员工编号插入员工 3)通过员工编号删除员工 4)按工资升序输出所有雇员的应交所得税清单 create or replace package emp_man is record2 emp%rowtype; function pers(v_no %type)return number; procedure counts; end emp_man; create or replace package body emp_man is function per

11、s(v_no %type)return number is v_sal number:=0; begin select sal* into v_sal from emp where empno = v_no; return v_sal; end; procedure counts is cursor cursor2 is select * from emp ; record3 emp%rowtype; v_sal2 number:=0; begin open cursor2; fetch cursor2 into record3; while cursor2%found loop v_sal2:=pers; | |v_sal2); fetch cursor2 into record3; end loop; close cursor2; end; end emp_man;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号