dbms_pipe

/*
dbms_pipe 用于同一例程在不同会话之间进行管道通信;
共用管道是所有数据库用户都可以访问;
私有管道只能由建立者数据库用户访问;
授权 – grant excute on dbms_pipe to scott;
*/

– 1,create_pipe
/*
该函数建立私有或共有管道;
若返回0,表示管道建立成功;
*/
declare
flag int;
begin
flag:= dbms_pipe.create_pipe(‘public_pipe’,2561,false);
if flag=0 then
dbms_output.put_line(‘管道建立成功……….’);
end if;
end;

– 2,pack_message
/*
把本地消息写入缓存区,
为把消息发送到管道中做准备;
*/

declare
name emp.empname%type;
v_sal emp.sal%type;
v_rowid rowid;
begin
select empname,sal ,rowid into name ,v_sal,v_rowid from emp where empno = 8;
dbms_pipe.pack_message(name);
dbms_pipe.pack_message(v_sal);
dbms_pipe.pack_message(v_rowid);
end;

– 3,send_message
/*
该函数将本地缓冲区的消息发送到管道;
0 —-成功
1—–超时
3—–中断
*/
declare
flag int ;
begin
flag:=dbms_pipe.send_message(‘public_pipe’);
if flag = 0 then
dbms_output.put_line(‘向管道发送消息成功……………’);
end if;
end;

–4,recieve_message
/*
该函数将接收管道消息,把他放置本地缓存区
0 —-接收成功
1—–接收超时
2——本地缓存区不能容纳管道消息
3—–中断
*/

declare
flag int ;
begin
flag:=dbms_pipe.receive_message(‘public_pipe’);
if flag = 0 then
dbms_output.put_line(‘接受管道消息成功……………’);
end if;
end;

–5,next_item_type
/*
该函数将接收管道消息后,确定本地缓存区的下一条消息的类型
o—该管道没有任何消息
6—number
9—-varchar2
11—-rowid
12—-date
23—raw
*/
declare
no int;
begin
no:=dbms_pipe.next_item_type;
dbms_output.put_line(‘管道消息类型编号为:’ || no);
end;

—6,unpack_masage
/*
recieve_message把消息放入缓冲区后;
unpack_message 该过程用于将消息写入变量中;
*/

declare
mass number(20);
begin
dbms_pipe.unpack_message(mass);
dbms_output.put_line(mass);
end;

—7,remove_masage
/*
该函数用于删除管道
0 —删除成功
*/

declare
no int;
begin
no := dbms_pipe.remove_pipe(‘paublic_pipe’);
if no =0 then
dbms_output.put_line(‘管道删除成功…….’);
end if;
end;

–8.purge
/*
用于清除管道里的消息
*/

begin
dbms_pipe.purge(‘public_pipe’);
end;

– 9,reset_buffer
/*
复位管道缓冲区
因为所有管道都共享单个管道缓冲区。所以在使用新管道时,要复位管道缓冲区;

*/

begin
dbms_pipe.reset_buffer;
end;

– 10,unique_session_name
/*
为特定会话返回唯一的名称;
*/

declare
name varchar2(100);
begin
name := dbms_pipe.unique_session_name;
dbms_output.put_line(name);
end;


/*
管道使用特例
*/

–建立过程send_message

grant execute on dbms_pipe to system;
create or replace procedure send_message(
pipename 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;

 --建立过程recieve_message

 create or replace procedure recieve_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);
       dbms_output.put_line(message);
       flag:= dbms_pipe.remove_pipe(pipename);
    end if;    
end;

–使用过程
begin
send_message(‘public_pipe’,’how are you ‘);
end;

declare
message varchar2(100);
begin
recieve_message(‘public_pipe’,message);
dbms_output.put_line(message);
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值