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程序设计过程中,即使是写得最好的程序也可能会遇到错误或未预料 ...
随机推荐
- DBA_Oracle DBA常用表汇总(概念)
2014-06-20 Created By BaoXinjian
- UVa 297 Quadtrees(树的递归)
Quadtrees 四分树就是一颗一个结点只有4个儿子或者没有儿子的树 [题目链接]UVa 297 Quadtrees [题目类型]树的递归 &题意: 一个图片,像素是32*32,给你两个先序 ...
- Linux查看程序端口占用情况(转载)
From:http://www.cnblogs.com/benio/archive/2010/09/15/1826728.html 今天发现服务器上Tomcat 8080端口起不来,老提示端口已经被占 ...
- iOS 批量打包--Shell脚本
由于公司有批量打包的需要,只是渠道号不一样,网上搜索一番,大致有两个方式:a) 从源程序一次性打出所有渠道的ipa包,大概的思路就是利用脚本循环执行打包过程,而每次打包前都通过脚本修改项目中存放渠道号 ...
- 真正的轻量级WebService框架——使用JAX-WS(JWS)发布WebService
WebService历来都很受重视,特别是Java阵营,WebService框架和技术层出不穷.知名的XFile(新的如CXF).Axis1.Axis2等. 而Sun公司也不甘落后,从早期的JAX-R ...
- IntelliJ IDEA调整控制台输出字体大小
File->Settings->Editor->Colors & Fonts->Console Font Size: 16
- OC基础(4)
NSString 类介绍及用法 结构体成员变量 对象和方法之间的关系 对象作为方法的参数连续传递 *:first-child { margin-top: 0 !important; } body &g ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem J
Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...
- Grunt - Karma 单元测试
Karma 是 Goolge 开源的一个 Test runner, 可以配合 Grunt 使用. 1. 相关插件介绍 1.1 Karma 的官网 http://karma-runner.github. ...
- IIS安全工具UrlScan介绍 ASP.NET 两种超强SQL 注入免费解决方案( 基于IIS,使用免费工具) 批改或隐藏IIS7.5的Server头信息 移除X-Powered-By,MVC,ASP.NET_SessionId 的 HTTP头或者cookie名称
微软给了我们一个很好的工具用来使IIS安全的运行-------UrlScan,下面是它的配置文件介绍 [options]UseAllowVerbs=1 ; 若为1,则使用 ...