Get result set in plsql -


am wondering if there rewriting suggestions functions such generating recurrence dates between 2 dates - generate_recurrences() link recurrency recurrency events

in plsql? returns setof date, in plsql can't figure out how resultset dates , looping return next next_date, next returns next date on list.

i tried rewrite in plsql return of 1 date, because can't find out how return resultset in plsql, i've tried:

create or replace function generate_recurrence( rec in varchar2,                                 start_date in timestamp,                                 end_date in timestamp ) return  timestamp     next_date timestamp := start_date;     duration  interval  day second;     day       interval  day second; begin  if recurs = 'none'     return next_date;  elsif recurs = 'daily'     duration :=  interval '1' day ;     while next_date <= end_date loop      return next_date + duration; end if; end; 

i wrote following pipelined function while ago. it's not exactly you're asking for, gives resultset that's range of dates, should able match needs.

it requires create type object hold return value , used existing object instead of creating custom one. should modify use object big enough (and use date type instead of string). functionality you're asking for.

enjoy!

create or replace function date_range_stream(start_date_in in date,                                              end_date_in   in date) return rpt_results_10_obj_type_type     deterministic     pipelined     /*          parameters:     start_date_in - first date return (truncated)                         end_date_in   - last date return, inclusive          results:        date string formatted mm/dd/yyyy          author:         stew stryker          usage:          select to_date(text01, 'mm/dd/yyyy') a_date                           table(aeo.aeo_misc_tools.date_range_stream('01-mar-2009', sysdate))                         returns rows starting date current          requires definition of following object:              create or replace type rpt_results_10col_obj object             (   seq_num number,                 place varchar2(20),                 rep_info varchar2(20),                 text01 varchar2(512),                 text02 varchar2(512),                 text03 varchar2(512),                 text04 varchar2(512),                 text05 varchar2(512),                 text06 varchar2(512),                 text07 varchar2(512),                 text08 varchar2(512),                 text09 varchar2(512),                 text10 varchar2(512));       */     cur_date date := trunc(start_date_in);     date_row rpt_results_10col_obj := aeo.rpt_results_10col_obj(null,                                                                 null,                                                                 null,                                                                 null,                                                                 null,                                                                 null,                                                                 null,                                                                 null,                                                                 null,                                                                 null,                                                                 null,                                                                 null,                                                                 null); begin     while cur_date <= trunc(end_date_in)     loop         date_row.text01 := to_char(cur_date, 'mm/dd/yyyy');         pipe row(date_row);         cur_date := cur_date + 1;     end loop;      return;  exception     when no_data_found         return;     when others         dbms_output.put_line('exception in aeo.aeo_misc_tools.date_range_stream - ' || sqlcode || ': ' ||                              sqlerrm);         raise;         return; end date_range_stream; 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -