create or replace type rang_date_tbl_type as table of date;
create or replace function get_range_date
(from_dt date default null,to_dt date default null)
 return rang_date_tbl_type pipelined is
 start_dt date;
 end_dt date;
 begin
     if from_dt>to_dt then
       raise_application_error(-20001,'开始日期比结束日期值大');
     end if;
     if from_dt is null then
       start_dt := trunc(sysdate,'mm');
       end_dt := last_day(sysdate);
       elsif to_dt is null then
         start_dt := trunc(from_dt,'mm');
         end_dt := last_day(from_dt);
        else
          start_dt := trunc(from_dt);
          end_dt := trunc(to_dt);
      end if;
      while start_dt <= end_dt loop
        pipe row(start_dt);
        start_dt := start_dt + 1;
      end loop;
      return;

 end;


管道函数示例

相关文章: