1. 简单的例子(返回单列的表)
1>创建一个表类型
create or replace type t_table is table of number;
2>创建函数返回上面定义的类型
create or replace function f_pipe(s number) return t_table pipelined as v_number number; begin for i in 1..s loop v_number := i; pipe row(v_number); end loop; return; end f_pipe; ;
3>测试
select * from table(f_pipe(5))
2.复杂一点的例子
1>创建一个表类型(有多个列)
create or replace type obj_table as object ( id int, name varchar2(50) )
2>创建函数返回上面定义的类型
create or replace function f_pipe(s number) return t_table pipelined as v_obj_table obj_table; begin for i in 1..s loop v_obj_table := obj_table(i,to_char(i*i)); pipe row(v_obj_table); end loop; return; end f_pipe;
3>测试
select * from table(f_pipe(5))