Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

CREATE N NUMBER of rows for a date range

BeefStuAug 21 2022

I have the following code, which I use to generate test data and it works okay.

Is there a way I can wrap this to create a PIPELINED function that accepts a from and to date instead of hard coding UNION ALL for each date I need data for?

For example, let's say I want to create a N NUMBER of rows of data for each day from date'2022-08-01'   - date'2022-08-31'   where the DEFAULT for N=100. If possible, could there be only one generic solution that handles both dates and timestamps?

I'm certainly open to any alternative ways to achieve this goal if a PIPELINED function isn't the best way to proceed.

Thanks in advance to all who answer and your expertise. Below is what I'm using now.

alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'

select * from (   
  select date'2022-08-01'   
           + numtodsinterval ( level , 'minute' )   
      + dbms_random. value datetime  
  from   dual  
  connect by level <= 100  
  union  all  
select date'2022-08-02'   
           + numtodsinterval ( level , 'minute' )   
           + dbms_random.value datetime  
  from   dual  
  connect by level <= 100  
) 
This post has been answered by mathguy on Aug 21 2022
Jump to Answer
Comments
Post Details
Added on Aug 21 2022
12 comments
1,362 views