Oracle的管道 dbms pipe 通訊

2021-09-30 05:52:59 字數 2013 閱讀 9034

oracle的管道(dbms_pipe)我今天在看乙個文件時,其中提到了oracle管道的應用,我的理解是管道就是會話間通訊的一種方式,類似於程式的程序間通訊.

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;

/

oracle管道輸出

通常我們會在oracle中用dbms output輸出除錯資訊,但dbms output只能在呼叫過程完成才返回結果,不能實時輸出的。這意味著通常我們經常要等幾分鐘或更長的時間才能看到除錯資訊,那怎麼才能實現實時輸出呢?如果想實時輸出可以通過寫表或者寫日誌的方式進行,和pipe row管道輸出的方法...

oracle 管道流函式

管道流函式 1 先定義 物件類中 比如 create or replace type obj cjgzl is object mjvarchar2 20 民警 sspcsvarchar2 12 派出所 sqdmvarchar2 20 社群 fwslnumber 10 房屋數 czrksnumber ...

Oracle管道函式示例

oracle的管道函式需要定義下面的三樣 record object type 定義乙個record或object型別的變數,這個變數用於表示返回結果集的一行資料,有點像c 中的datarow類。table type 定義乙個集合型別,這個型別由record object type填充。這個型別也可...