Oracle: return the result set from a CTE from a inline table function
I am able to get a similiar function working in TSQL but I am a relative newb开发者_运维问答ie to PL/SQL, I'm hopeing someone can explain to me why this function declaration will not compile.
t_interval_list_table is a table type of objects t_interval which has a single attribute of varchar2(20). Interval_Get_udf just returns a formatted string of type 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;
You probably can simplify the query in your PL/SQL procedure:
SELECT t_interval(Interval_Get_udf(TRUNC(startTime) + ROWNUM/24 , 1))
BULK COLLECT INTO intervalList
FROM dual
CONNECT BY LEVEL <= 65536
That might get rid of the error.
Its hard to read this one so I'm probably wrong...
Are you just missing the semi-colon at the end of the following:
t_interval_list_table := t_interval_list_table();
精彩评论