首页 > Linux操作系统 > Linux操作系统 > 整型序号产生器(七)
本节介绍使用Pipelined函数的方法产生连续整数。
需要使用nested table type或 varry type.我们这使用一个名为INTEGER_TABLE_TYPE的类型。
desc integer_table_type
integer_table_type TABLE OF NUMBER(38)
在数据库中定义这么一个函数:
create function integer_series
(
p_lower_bound in number,
p_upper_bound in number
)
return integer_table_type
pipelined
as
begin
for i in p_lower_bound .. p_upper_bound
loop
pipe row(i);
end loop;
return;
end;
/
我们介绍如何使用INTEGER_SERIES 函数.
select *
from table( integer_series(-5,7) ) ;
COLUMN_VALUE
------------
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
在我们的day of the week 的例子使用这种方法:
select
i.column_value as day_of_week ,
t.val
from
table( integer_series(0,6) ) i
left outer join t
on ( i.column_value = t.day_of_week )
order by
i.column_value
;
DAY_OF_WEEK VAL
----------- ----------
0
1 100
2
3 300
4 400
5 500
6
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9036/viewspace-603/,如需转载,请注明出处,否则将追究法律责任。