管道函数

管道函数是一种比较特殊的函数,其返回值为集合类型。

在PL/SQL中,管道函数和表函数、游标一起联合使用能实现一些比较复杂的功能,当和并行处理一起使用时,还能较大的改善性能。

使用方法:

  1. 创建一个对象来保存数据

Create or replace type obj_dept as object(

           DEPARTMENT_ID    NUMBER(4),

           DEPARTMENT_NAME  VARCHAR2(30 BYTE),

           MANAGER_ID       NUMBER(6),

           LOCATION_ID      NUMBER(4)

);

  1. 创建一个表类型

Create or replace type ty_dept_table is table of obj_dept;

  1. 创建管道函数

Create or replace function func_build_dept(

           Dept_id number,

           Dept_name varchar2,

           Mgr_id number,

           Loc_id number

)

Return ty_dept_table pipelined is

v_d  obj_dept;

begin

           v_d := obj_dept(dept_id,dept_name,mgr_id,loc_id);

     pipe row(v_d);

     return;

end;

  1. 测试管道函数

Select * from table(func_build_dept(1200, 'ISD', 9900, 1705));

原文地址:https://www.cnblogs.com/lvxiaowei/p/4285982.html