Oracle:从内联表函数返回CTE的结果集

时间:2011-07-19 13:09:10

标签: plsql oracle10g common-table-expression user-defined-functions

我能够在TSQL中使用类似的功能,但我是PL / SQL的新手,我希望有人可以向我解释为什么这个函数声明无法编译。
t_interval_list_table是对象的表类型t_interval,其具有单个属性varchar2(20)。 Interval_Get_udf只返回varchar(2)

类型的格式化字符串
create or replace
FUNCTION  fn_ExplodeIntervals (
  startTime IN timestamp,
  endTime IN timestamp,
  inputInterval IN int)
  RETURN t_interval_list_table   AS  intervalList t_interval_list_table := t_interval_list_table()
BEGIN

 with SET0 as( select 1 from dual union all select 1 from dual)
   , SET1 as ( select 1 from SET0 s1, SET0 s2)
   , SET2 as ( select 1 from SET1 s1, SET1 s2)
   , SET3 as ( select 1 from SET3 s1, SET3 s2)
   , SET4 as ( select 1 from SET4 s1, SET4 s2)
   , ControlSet AS (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 1 from Dual)) rid  FROM SET4)

  select t_interval(Interval_Get_udf(TO_TIMESTAMP(startTime, 'dd/mm/yyyy') + rid/24 , 1))
  into intervalList
  from ControlSet;

  RETURN intervalList;

END fn_ExplodeIntervals;

2 个答案:

答案 0 :(得分:0)

您可以在PL / SQL过程中简化查询:

SELECT t_interval(Interval_Get_udf(TRUNC(startTime) + ROWNUM/24 , 1))
BULK COLLECT INTO intervalList
FROM dual 
CONNECT BY LEVEL <= 65536

这可能会消除错误。

答案 1 :(得分:0)

很难读懂这个,所以我可能错了......
你是不是在下面的末尾错过了分号:
t_interval_list_table:= t_interval_list_table( );