dbms_pipe(管道用法)

本文介绍如何在Oracle数据库中使用DBMS_PIPE包实现不同会话间的管道通信。包括创建和发送消息到私有管道与公共管道,以及如何接收这些消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、再一个session中建立管道

 

set serveroutput on;
declare
v_statpipe1 
integer;
v_statpipe2 
integer;
v_pubchar 
varchar2(100):='This is a text string';
v_pubdate date :
= sysdate;
v_pubnum 
number :=109;

begin
v_statpipe1 :
= dbms_pipe.create_pipe('myprivatepipe');

if v_statpipe1=0 then
dbms_pipe.pack_message(
'privateline1');
dbms_pipe.pack_message(
'privateline2');
v_statpipe1 :
=dbms_pipe.send_message('myprivatepipe');
end if;

dbms_pipe.pack_message(v_pubchar);
dbms_pipe.pack_message(v_pubdate);
dbms_pipe.pack_message(v_pubnum);
--pub pipe
v_statpipe2 := dbms_pipe.send_message('mypublicpipe');
dbms_output.put_line(
'the status of your private pipe is '||v_statpipe1);
dbms_output.put_line(
'the status of your public pipe is '||v_statpipe2);
end;
/

 2、再另外一个session中收取管道中的消息

 

set serveroutput on;
declare
v_statpipe1 
integer;
v_statpipe2 
integer;
v_holdtype 
integer;
v_holdchar 
varchar2(100);
v_holddate date;
v_holdnum 
number;
begin
v_statpipe1 :
= dbms_pipe.receive_message('myprivatepipe',15);
dbms_pipe.unpack_message(v_holdchar);
dbms_output.put_line(v_holdchar);
dbms_pipe.unpack_message(v_holdchar);
dbms_output.put_line(v_holdchar);

--public pipe
v_statpipe2 := dbms_pipe.receive_message('mypublicpipe',10);
loop
v_holdtype :
= dbms_pipe.next_item_type;
if v_holdtype=0 then exit;
elsif v_holdtype
=6 then dbms_pipe.unpack_message(v_holdnum);
elsif v_holdtype
=9 then dbms_pipe.unpack_message(v_holdchar);
elsif v_holdtype
=12 then dbms_pipe.unpack_message(v_holddate);
end if;
end loop;

dbms_output.put_line(v_holddate
||'  '||v_holdnum||'  '||v_holdchar);
end;
/

pipe相关的另外一个函数就是 remove_pipe();

status:=dbms_pipe.remove_pipe('myprivatepipe');
status:=dbms_pipe.remove_pipe('mypublicpipe');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值