整型序号产生器(七)

Pipelined函数方法

本节介绍使用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

 
请使用浏览器的分享功能分享到微信等