Oracle笔记 十三、PL/SQL面向对象之package
--将方法和过程用包定义
create or replace package pkg_emp
as
--输入员工编号查询出员工信息
procedure pro_findInfo(
in_empno emp2.empno%type,
out_name out emp2.ename%type,
out_sal out emp2.sal%type
);
--根据部门编号修改本部门员工工资
procedure pro_editInfo(
in_emp_record emp2%rowtype,
out_flag out boolean
);
--输入新员工信息并保存到数据库
procedure pro_addInfo(
in_emp_new_record emp2%rowtype
);
--统计工资信息
function fun_sum(
num_a number,
num_b number
) return number;
end pkg_emp;
--实现包
create or replace package body pkg_emp
as
--输入员工编号查询出员工信息
procedure pro_findInfo(
in_empno emp2.empno%type,
out_name out emp2.ename%type,
out_sal out emp2.sal%type
)
as
begin
select ename, sal into out_name, out_sal from emp2 where empno = in_empno;
end pro_findInfo;
--根据部门编号修改本部门员工工资
procedure pro_editInfo(
in_emp_record emp2%rowtype,
out_flag out boolean
)
is
begin
update emp2 set sal = in_emp_record.sal where deptno = in_emp_record.deptno;
out_flag := true;
/*exception
when no_data_found then
out_flag := false;
commit;*/
if (sql%rowcount < 1) then
out_flag := false;
else
out_flag := true;
commit;
end if;
end pro_editInfo;
--输入新员工信息并保存到数据库
procedure pro_addInfo(
in_emp_new_record emp2%rowtype
)
as
temp_sql varchar2(200);
begin
temp_sql := 'insert into emp2(empno, ename, sal, comm, deptno) values(:1, :2, :3, :4, :5)';
execute immediate temp_sql using in_emp_new_record.empno, in_emp_new_record.ename,
in_emp_new_record.sal, in_emp_new_record.comm, in_emp_new_record.deptno;
commit;
end;
--统计工资信息
function fun_sum(
num_a number,
num_b number
) return number
is
begin
return num_a + num_b;
end fun_sum;
end pkg_emp;
--测试1
declare
out_name emp2.ename%type;
out_sal emp2.sal%type;
begin
pkg_emp.pro_findInfo(7369, out_name, out_sal);
dbms_output.put_line(out_name);
dbms_output.put_line(out_sal);
end;
--测试2
select * from emp2;
declare
in_emp_record emp2%rowtype;
flag boolean;
begin
in_emp_record.deptno := &部门编号;
in_emp_record.sal := &员工工资;
pkg_emp.pro_editInfo(in_emp_record, flag);
if (flag = false) then
dbms_output.put_line('no');
else
dbms_output.put_line('yes');
end if;
end;
--测试3
declare
new_emp_record emp2%rowtype;
begin
new_emp_record.empno := &员工编号;
new_emp_record.ename := &姓名;
new_emp_record.sal := &工资;
new_emp_record.comm := &奖金;
new_emp_record.deptno := &部门编号;
pkg_emp.pro_addInfo(new_emp_record);
end;
--测试4
declare
sum_emp number;
begin
select pkg_emp.fun_sum(sal, nvl(comm, 0)) into sum_emp from emp2
where empno = &员工编号;
dbms_output.put_line('员工总工资:' || sum_emp);
end;
Oracle笔记 十三、PL/SQL面向对象之package的更多相关文章
- Oracle数据库之PL/SQL包
Oracle数据库之PL/SQL包 1. 简介 包(PACKAGE)是一种数据对象,它是一组相关过程.函数.变量.常量和游标等PL/SQL程序设计元素的组合,作为一个完整的单元存储在数据库中,用名称来 ...
- oracle instantclient basic +pl/sql 安装和配置
oracle instantclient basic +pl/sql 安装和配置 大家都知道,用PL/SQL连接Oracle,是需要安装Oracle客户端软件的,oracle客户端有点大,比较耗资源. ...
- oracle系列(四)PL/SQL
过程,函数,触发器是PL/SQL编写的,存储在oracle中的.PL/SQL是非常强大的数据库过程语言. PL/SQL优点:性能,模块化,网络传输量,安全性缺点:移植性不好 简单分类:块:过程,函数, ...
- 每周一书《Oracle 12 c PL(SQL)程序设计终极指南》
本周为大家送出的书是<Oracle 12 c PL(SQL)程序设计终极指南>,此书由机械工业出版社出版, 孙风栋,王澜,郭晓惠 著. 内容简介: <Oracle 12c PL/SQ ...
- 《oracle每日一练》免安装Oracle客户端使用PL/SQL
免安装Oracle客户端使用PL/SQL Oracle客户端挺招人烦的,部署连接它的应用通常需要先安装它的客户端,安装程序要求在目标机器上写注册表,假设你没有洁癖的话,你仍可能被下面的事情绊住:当你的 ...
- Oracle 客户端安装 + pl/sql工具安装配置
Oracle 客户端安装 + pl/sql工具安装配置 下载oracle客户端,并在本地安装. 11g下载地址为: http://www.oracle.com/technetwork/databas ...
- Oracle数据库之PL/SQL触发器
Oracle数据库之PL/SQL触发器 1. 介绍 触发器(trigger)是数据库提供给程序员和数据分析员来保证数据完整性的一种方法,它是与表事件相关的特殊的存储过程,它的执行不是由程序调用,也不是 ...
- Oracle数据库之PL/SQL过程与函数
Oracle数据库之PL/SQL过程与函数 PL/SQL块分为匿名块与命名块,命名块又包含子程序.包和触发器. 过程和函数统称为PL/SQL子程序,我们可以将商业逻辑.企业规则写成过程或函数保存到数据 ...
- Oracle数据库之PL/SQL异常处理
Oracle数据库之PL/SQL异常处理 异常指的是在程序运行过程中发生的异常事件,通常是由硬件问题或者程序设计问题所导致的. PL/SQL程序设计过程中,即使是写得最好的程序也可能会遇到错误或未预料 ...
随机推荐
- 将博客搬至51CTO
为了统一博客文章,将文章搬至51cto个人博客
- 在dom4j中使用XPath
package com.wzh.test.xpath; import java.io.File; import org.dom4j.Document; import org.dom4j.Documen ...
- arm-linux-gcc 常用参数讲解 gcc编译器使用方法
我们需要编译出运行在ARM平台上的代码,所使用的交叉编译器为 arm-linux-gcc.下面将arm-linux-gcc编译工具的一些常用命令参数介绍给大家.在此之前首先介绍下编译器的工作过程,在使 ...
- Oracle中的多表查询
多表查询 l 笛卡尔积: N*M l 使用关联字段消除笛卡尔积的多余数据: SELECT EMP.*,DEPT.DNAME,DEPT.LOC FROM EMP, DEPT WHERE EMP.DEPT ...
- 有没有一行文件字过多后可以省略号显示,我说的不是用其他样式,BT本身有没有?谢谢
.text-overflow {display: inline-block;max-width: 200px;overflow: hidden;text-overflow: ellipsis;whit ...
- java中的xml与实体类之间的映射
实体类: package xml; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class User ...
- 【译】深入理解python3.4中Asyncio库与Node.js的异步IO机制
转载自http://xidui.github.io/2015/10/29/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3python3-4-Asyncio%E5%BA%93% ...
- C Primer Plus(第五版)2
在本章中你将学习下列内容------------------------------------------------------------------1.运算符:= 2.函数:main(),pr ...
- Android-ImageView.ScaleType
ImageView的Scaletype决定了图片在View上显示时的样子,如进行何种比例的缩放,及显示图片的整体还是部分,等等. 设置的方式包括: 1. 在layout xml中定义android:s ...
- [转]windows下设置socket的connect超时
原文地址:http://www.cnblogs.com/BloodAndBone/archive/2012/05/22/2513338.html 变相的实现connect的超时,我要讲的就是这个方法, ...