说明:本文为面向PL/SQL开发初学者的指导手册
标签:PL/SQL、pipe、管道、循环、优化、加速、dbms_pipe
释义:DBMS_PIPE管道包是Oracle11gR1引入的功能,用来在同一例程(实例)的不同会话之间进行通信
优点:由于PL/SQL中的pipe管道拥有高性能特性,所以常用于循环体的数据传输
易学:文中删去了不需要的多余部分,让初学者一目了然一学就会
温馨提示:如果您发现本文哪里写的有问题或者有更好的写法请留言或私信我进行修改优化
--创建带有管道的存储过程
create or replace procedure p_select
is
i simple_integer := 1;
j simple_integer := 2000000000;
v simple_integer := 0;
message char(10);
pipename char(20) := 'pipe_zzt_select';
begin
for i in 1 .. j loop
select /*+ no_result_cache */
count(*) into v
from zzt.info a, zzt.info b
where a.sal != b.sal
and a.id < 100
and a.sal < 50000;
if dbms_pipe.receive_message(pipename, 0) = 0 then
dbms_pipe.unpack_message(message);
exit when message = 'stop';
end if;
end loop;
v := dbms_pipe.remove_pipe(pipename);
end;
/
--给循环体发送停止信息(pipe_zzt_select)
set timing on
declare
pipename char(20) :='pipe_zzt_select';
message char(10) :='stop';
flag pls_integer;
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 ;
/
※ 如果您觉得文章写的还不错, 别忘了在文末给作者点个赞哦 ~
over