惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
W
WeLiveSecurity
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
F
Full Disclosure
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
G
Google Developers Blog
C
Check Point Blog
GbyAI
GbyAI
A
About on SuperTechFans
V
Vulnerabilities – Threatpost
T
The Blog of Author Tim Ferriss
T
Tor Project blog
AWS News Blog
AWS News Blog
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
MongoDB | Blog
MongoDB | Blog
Latest news
Latest news
aimingoo的专栏
aimingoo的专栏
U
Unit 42
Y
Y Combinator Blog
P
Privacy International News Feed
Cisco Talos Blog
Cisco Talos Blog
S
Securelist
S
Schneier on Security
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Attack and Defense Labs
Attack and Defense Labs
P
Proofpoint News Feed
C
Cisco Blogs
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
P
Privacy & Cybersecurity Law Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
罗磊的独立博客
Cloudbric
Cloudbric
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog

博客园 - osbreak

ros2::tf2 QML::qml与c++数据交互 k8s:: Service 管理 deployment postgresql 索引 postgresql 基本类型 postgresql 基础运维 PLSQL 触发器 PLSQL 执行块 PLSQL 基础数据类型 PLSQL oracle安装部署 mysql事务与隔离 mysql慢查询分析 mysql建增删改查 mysql常用总结 (9)libevent 常用设置 (8)libevent 构建libevent http服务,支持文件下载 (7)libevent filter(过滤器) (6)libevent定时器 (5)libevent evbuffer
PLSQL 程序包
osbreak · 2023-12-10 · via 博客园 - osbreak

程序包是对相关过程、函数、变量、游标和异常等对象的封装

  • 包部件可以以任意顺序出现
  • 并非所有部件都必须被使用
  • 对函数/事件的声明 必须是前向声明
  • 在编译包主体时先编译包规范说明
  • 包主体也不是必须的
  • 包内定义的函数/过程对外是可见的
  • 包内定义的函数/过程可以被重载
  • 二个子程序的参数仅在名字或模式上是不同的,那么不能重载
  • 不能根据反回类型的不同来重载二个函数

程序包的定义和使用规范

  • 包规范
  • 包主体
  • 包和作用域
  • 重载包中子程序
  • 包的初始化
  • 包和相关性

包的定义形式如下:

PACKAGE BODY 包名 IS
	变量名说明
	游标说明
	游标申明
	例外说明
	记录说明
	plsql说明
	过程体
	函数体
BEGIN 
	语句序列
END[包名];
CREATE OR REPLACE PACKAGE BODY pack_me AS
  PROCEDURE order_proc (orno VARCHAR2) IS
    stat CHAR(1);
  BEGIN
    SELECT ostatus INTO stat FROM order_master
    WHERE orderno = orno;
    ……
  END order_proc;
  FUNCTION order_fun(ornos VARCHAR2)
  RETURN VARCHAR2
  IS
    icode   VARCHAR2(5);
    ocode   VARCHAR2(5);
  BEGIN
  ......
  END order_fun;
END pack_me;
/* 示例 */
/* 包定义 */
create or replace package toyspack 
is 
	procedure updatetoyprice;
	function augtoyprice return number;
end;
---------------------------------------
/* 包体 */
create or replace package body toyspack
is
	/* 存储过程 */
	procedure updatetoyprice
	as
		augprice number;
		begin
		augprice:=augtoyprice;
		while(augprice<=400)
		loop
		update my_toys
		set price=case
			when pricex1.1<50 then pricex1.1
				else 
			price;
			end ;
		augprice:=augtoyprice;
		end loop;
	commit;
	end;
	/* 函数 */
	function augtoyprice
		return number
	as
		augprice number;
	begin
		select avg(price) into augprice from my_toys;
		return augprice;
	end;
end;
/* 包调用 */
execute toyspack.updatetoyprice;

程序包中的游标

游标的定义分为游标规范和游标主体两部分
在包规范中声明游标规范时必须使用 RETURN 子句指定游标的返回类型
RETURN子句指定的数据类型可以是:

  • 用 %ROWTYPE 属性引用表定义的记录类型
  • 程序员定义的记录类型
SQL> CREATE OR REPLACE PACKAGE BODY cur_pack AS
 CURSOR ord_cur(vcode VARCHAR2)
 RETURN order_master%ROWTYPE IS 
 SELECT * FROM order_master WHERE VENCODE=vcode;
 PROCEDURE ord_pro(vcode VARCHAR2) IS
   or_rec order_master%ROWTYPE;
 BEGIN
  OPEN ord_cur(vcode); 
  LOOP
    FETCH ord_cur INTO or_rec;
    EXIT WHEN ord_cur%NOTFOUND;
    DBMS_OUTPUT.PUT_LIne(’返回的值为' || or_rec.orderno);
  END LOOP;
 END ord_pro;
END cur_pack;