dbms_pipe(管道用法)

来源:互联网 发布:php wget 下载文件 编辑:程序博客网 时间:2024/06/05 00:28

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');