1、概述

说明:Oracle管道类似UNIX系统的管道,但不采用OS机制实现,管道信息被缓存到SGA中,当关闭例程时会丢失管道信息,建立公用管道所有数据库用户都可访问,私有管道只能由建立这访问。
作用:用于在同一例程程的不同会话之间进行管道通信.注意,如果用户要执行包dbms_pipe中的过程和函数,则必须要为用户授权.
sql>conn sys/oracle as sysdba;
sql>grant execute on dbms_pipe to scott;

2、包的组成

1)、create_pipe
作用:该函数用于建立公用管道或私有管道.如果将参数private设置为TRUE,则建立私有管道;如果设置为FALSE,则建立公用管道.
语法:dbms_pipe.create_pipe(pipename
in varchar2,maxpipesize in integer default 8192,private in boolean
default true) return integer;
其中,pepename指定管道名称,maxpipesize指定管道消息的最大尺寸,private指定管道类型,函数返回0则成功,反之失败。

2)、pack_message
作用:该过程用于将变量写入到本地消息缓冲区。
说明:为了个管道发消息,首先使用过程pack_message将消息写入本地消息缓冲区,然后使用send_message将消息发送到管道。
语法:dbns_pipe.pack_message(item in varchar2/nchar2/number/date);
dbns_pipe.pack_message_raw(item in raw);
dbns_pipe.pack_message_rowid(item in rowid);

3)、send_message
作用:该函数用于将本地消息缓冲区中的内容发送到管道。
语法:dbms_pipe.send_message(pipename
in varchar2,timeout in integer defalut maxwait,maxpipesize in integer
default 8192) return integer;
其中,timeout指定发送消息的超时时间,0成功1超时3中断。

4)、receive_message
说明:该函数用于接收管道消息,并将接收到的消息写入到本地消息缓冲区。当接收完管道信息之后,会删除管道消息,管道消息只能被接收一次。
语法:
dbms_pipe.receive_message(pepename in varchar2,timeout in integer default maxwait) return integer;
其中,返回0接受成功,返回1超时,返回2本地缓冲区不能容纳管道消息,返回3发生中断。

5)、next_item_type
说明:该函数用于确定本地消息缓冲区下一项的数据类型。在调用receive_message之后调用。
语法:dbms_pipe.next_item_type return integer;
其中,如果该函数返回0,则表示管道没有任何消息;如果返回6,则表示下一项的数据类型为number;如果返回9,则表示下一项的数据类型为varchar2;
如果返回11,则表示下一项的数据类型为rowid;如果返回12,则表示下一项的数据类型为date;如果返回23,则表示下一项的数据类型为raw.

6)、unpack_message
作用:该过程用于将消息缓冲区的内容取出来写入到变量中,每次只能取一条,需要取出多条需要多次调用。
说明:在使用函数receive_message接收到管道消息之后,应该使用过程unpack_message取得消息缓冲区的消息。
语法:dbms_pipe.unpack_message(item out varchar2\nchar\number\date);
dbms_pipe.unpack_message_raw(item out raw);
dbms_pipe.unpack_message_rowid(item out rowid);、

7)、remove_pipe
作用:该函数用于删除已经建立的管道
语法:dbms_pipe.remove_pipe(pepename in varchar2) return integer;
其中,函数返回0表示成功,否则会显示错误信息。

8)、purge
说明:该过程用于清除管道中的内容。
语法:dbms_pipe.purge(pipename in varchar2);

9)、reset_buffer
说明:该过程用于复位管道缓冲区,因为所有管道都共享单个管道缓冲区,所以在使用新管道之前应该复位管道缓冲区。
语法:dbms_pipe.reset_buffer;

10)、unique_session_name
说明:该函数用于为特定会话返回惟一的名称,并且名称的最长度为30字节,对同一会话其值不变。
语法:dbms_pipe.unique_session_name

3、包的应用

1)、综合例子1
declare
falg int;
v_ename emp.ename%type;
v_sal emp.sal%type;
v_rowid rowid;
item_no int;
message varchar2(100);
v_session varchar2(200);
begin
flag := dbms_pipe.create_pipe('public_pipe', 8192, false);
if flag = 0 then
dbms_output.put_line('建立公用管道成功');
end if;
select ename,sal,rowid into v_ename,v_sal,v_rowid from emp where empno=7788;
dbns_pipe.pack_message(v_ename||','||v_sal||','||v_rowid);
flag :dbms_pipe.send_message('PUBLIC_PIPE');
if flag = 0 then
dbms_output.put_line('发送成功');
end if;
flag := dbms_pipe.receive_message('PUBLIC_PIPE');
if flag = 0 then
dbms_output.put_line('成功');
end if;
item_no := dbms_pipe.next_item_type;
dbms_output.put_line(item_no);
dbms_pipe.unpack_message(message);
dbms_output.put_line(message);
--remove_pipe
flag:=dbms_pipe.remove_pipe('PUBLIC_PIPE');
if flag = 0 then
dbms_output.put_line('删除成功');
end if;
--unique_session_name
v_session:=dbms_pipe.unique_session_name;
dbms_output.put_line(v_session);
end;

2)、综合例子2
使用管道是,一个会话需要将消息发送到管道中,另一个会话则需要接收管道消息。
发送消息到管道需要先将消息写入本地消息缓冲区,然后再发送到管道;
接收消息需要先使用本地消息缓冲区接收管道消息,然后从消息缓冲区取得具体消息。
create or replace procedure send_message(pepename varchar2,message varchar2) is
flag int;
begin
flag:=dbms_pipe.create_pipe(pipename);
if flag=0 then
dbms_pipe.pack_message(message);
flag:=dbms_pipe.send_message(pipename);
end if;
end send_message;

create or replace procedure receive_message(pipename varchar2,message out varchar2) is
flag int;
begin
flag:=dbms_pipe.receive_message(pipename);
if flag=0 then
dbms_pipe.unpack_message(message);
flag:=dbms_pipe.remove_pipe(pipename);
end if;
end receive_message;

会话一:exec send_message('pipe1','你好');
会话二:
var message varchar2(100)
exec scorr.receive_message('pipe1',:message)
print message

三、dbms_pipe(类似UNIX系统的管道)的更多相关文章

  1. UNIX 系统上的文本操作简介

    http://www.oschina.net/question/129540_53561 UNIX 的基本哲学之一就是创建只做一件事并将这一件事做好的程序(或进程).这一哲学要求认真考虑接口以及结合这 ...

  2. 《Linux/Unix系统编程手册》 时间子系统

    Linux下操作系统编程有两本经典APUE即<Advanced Programming in the UNIX Environment>和TLPI<The Linux Program ...

  3. 《Linux/UNIX系统编程手册》第63章 IO多路复用、信号驱动IO以及epoll

    关键词:fasync_helper.kill_async.sigsuspend.sigaction.fcntl.F_SETOWN_EX.F_SETSIG.select().poll().poll_wa ...

  4. Unix及类Unix系统文本编辑器的介绍

    概述 Vim是一个类似于Vi的著名的功能强大.高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性.VIM是纯粹的自由软件. Vim普遍被推崇为类Vi编辑器中最好的一个,事实上真正的劲敌来自Em ...

  5. UNIX系统的显示时间何时会到达尽头

    本文分为三个小块: 一.UNIX系统中时间的存储形式: 二. time_t 的最大值是多少: 三. 将time_t 的最大值转化为真实世界的时间: #---------------------# # ...

  6. (三) 一起学 Unix 环境高级编程 (APUE) 之 文件和目录

    . . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编 ...

  7. 《Linux/Unix系统编程手册》读书笔记5

    <Linux/Unix系统编程手册>读书笔记 目录 第8章 本章讲了用户和组,还有记录用户的密码文件/etc/passwd,shadow密码文件/etc/shadow还有组文件/etc/g ...

  8. UNIX系统接口

    UNIX系统接口 8.1 文件描述符 UNIX操作系统中,所有的外围设备(包括键盘和显示器)都被看作是文件系统中的文件.系统通过文件描述符来标识文件:标准输入为0,标准输出为1,标准错误为2. 当程序 ...

  9. Unix系统操作指令汇总

    一.目录及文件操作命令 1.1 ls 语法: ls [-RadCxmlnogrtucpFbqisf1] [目录或文件--] 说明: ls 命令列出指定目录下的文件,缺省目录为当前目录 ./,缺省输出顺 ...

随机推荐

  1. SSIS 2012 Error: An Integration Services class cannot be found

    升级SSIS到SQL Server 2012,服务器只安装了SSIS一个功能,应用程序执行dtsx包时报错如下: An Integration Services class cannot be fou ...

  2. Hive练习

    一.基础DDL练习 SHOW DATABASES; CREATE DATABASE IF NOT EXISTS db1 COMMENT 'Our database db1'; SHOW DATABAS ...

  3. python 实现3-2 问候语: 继续使用练习 3-1 中的列表,但不打印每个朋友的姓名,而为每人打印一条消息。每条消息都包含相同的问候语,但抬头为相应朋友的姓名。

    names = ['linda', 'battile', 'emly'] print(names[0].title() + " " + "good moning!&quo ...

  4. 微服务—分布式服务追踪sleuth和zipkin

    随着业务的发展,系统规模也会越来越大,各微服务间的调用关系也越来越错综复杂. 通常一个客户端发起的请求在后端系统中会经过多个不同的微服务调用来协同产生最后的请求结果, 在复杂的微服务架构系统中,几乎每 ...

  5. 微服务—ELK分布式日志框架

    在微服务架构下,微服务被拆分成多个微小的服务,每个微小的服务都部署在不同的服务器实例上,当我们定位问题,检索日志的时候需要依次登录每台服务器进行检索. 这样是不是感觉很繁琐和效率低下.所以我们还需要一 ...

  6. ashx 方法模板

    ; ); //查询字符串拼接 string searchparams = DTRequest.GetQueryString("jsonstring"); fooddetail mo ...

  7. 关于MVC打印问题,打印指定的内容

    首先你的内容一定要放在一个div中如下代码 <div id="divprint"> <table class="table table-striped ...

  8. linux版本安装pip

    因为一直在windows开发python程序,今天把python程序打成docker image镜像的时候,发现pip无法使用,并且使用yum 也无法安装,查找资料发现下面方法可用 1.python ...

  9. 20135320赵瀚青LINUX内核分析第一周学习笔记

    赵瀚青原创作品转载请注明出处<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.概述 第一周的学习内容主 ...

  10. windows 下获取父进程pid

    DWORD GetParentProcessID(DWORD dwProcessId) { LONG status; DWORD dwParentPID = (DWORD)-1; HANDLE hPr ...