How to generate the dates in order through functions

first to see the code example
create or replace function FNC_GET_DATE(p_businessdate varchar2) return date
as
v_date date;
begin

v_Date := to_date(p_businessdate,'mm/dd/yyyy') +10;

return v_date;
end;
Now I mean this function in a loop for N times and the first output of the function must be the entrance for the second call

Assuming that the initial value of p_businessdate be 01/01/2012 the output of the function should be 11/01/2012.

Now exit 11/01/2012 must be sent as input for the FNC_GET_DATE function, then the output should be 21/01/2012.

Now exit 21/01/2012 must be sent as input for the FNC_GET_DATE function, then the output should be 31/01/2012.

Assuming that the number of iterations to 4 outputs (here the value of N) should be something like this:
01/01/2012
01/11/2012
01/21/2012
01/31/2012
For this we need a function that has p_busdate and no_of_itereations as input parameter and the retrun type can be a sysrefcursor as shown below, once more:


01/01/2012
11/01/2012
21/01/2012
31/01/2012

Please notify.

Here's a basic idea.

I used a nested function to simulate the 'other' function, you need to call. I also didn't care to do things like manipulate strings and convert to date, but you get the idea.

create or replace function f_get_some_dates
(
      p_starting_date   date
   ,  p_how_many_dates  number
)
return sys_refcursor
as
   l_date_list    sys.odcidatelist  default sys.odcidatelist();
   l_current_date date  := p_starting_date;
   l_ref_cursor   sys_refcursor;

   function f_add_days
   (
      p_date   date
   )
   return date
   is
   begin
      return p_date + 10;
   end f_add_days;
begin

   for loop_idx in 1 .. p_how_many_dates
   loop
      l_current_date := f_add_days(l_current_date);
      l_date_list.extend;
      l_date_list(l_date_list.count)   := l_current_date;
   end loop;

   open l_ref_cursor for
   select *
   from table(cast(l_date_list as sys.odcidatelist))
   order by column_value asc;

   return l_ref_cursor;

end f_get_some_dates;
/

ME_TUBBZ?variable rc refcursor;
ME_TUBBZ?exec :rc := f_get_some_dates(trunc(sysdate, 'dd'), 2);

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
ME_TUBBZ?print :rc

COLUMN_VALUE
--------------------
08-JUL-2012 00 00:00
18-JUL-2012 00 00:00

2 rows selected.

Elapsed: 00:00:00.00
ME_TUBBZ?exec :rc := f_get_some_dates(trunc(sysdate, 'dd'), 4);

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
ME_TUBBZ?print :rc

COLUMN_VALUE
--------------------
08-JUL-2012 00 00:00
18-JUL-2012 00 00:00
28-JUL-2012 00 00:00
07-AUG-2012 00 00:00

4 rows selected.

Elapsed: 00:00:00.00
ME_TUBBZ?

See you soon,.

Tags: Database

Similar Questions

  • How to generate the script to insert data tables present in a

    How to generate the script to insert data from one table in an entire schema under environment sqlplus




    with toads it please help me please!

    905310 wrote:
    How to generate the script to insert data from one table in an entire schema under environment sqlplus
    with toads it please help me please!

    The correct method by using the pump of the database or import/export or unload the data in CSV format for loading using SQL * Loader.

    Generate instructions insert with literals is very bad choices - the bind variable is missing. It will be quite slow because many other CPU cycles are spend on hard analysis. The shared pool will become fragmented. This can cause errors of memory for other applications when they attempt to analyze SQLs for cursors.

  • How to generate the report on rules

    How to generate the report on rules with id recipient and with a few keyoword in a rule.

    The rule management dashboard has an integrated 'report rules', you can configure properties and input parameters.

    For rule management dashboard, click homes > Administration > rules. In the upper right, next to the date and time, click reports.

    You can also find these helpful videos: http://edocs.quest.com/foglight/5610/Foglight_Reports_videos.php

    Hope this helps,

    Shay

  • How to generate the array Diagnostic Utility ADU for Esxi server

    How to run Diagnostic Utility ADU or HP Insight Diagnostics HP Insight Diagnostics table to collect the status tables and logs data FRO an Esxi Server

    How to generate the array Diagnostic Utility ADU for Esxi server

    Example:

    Download the package .vib here: http://vibsdepot.hp.com/hpq/feb2013/esxi-5x-vibs/hpacucli/hpacucli-9.40-12.0.vib

    and place it on a store of data seen by the host...

    Install it using the CLI:

    software esxcli vib install d vmfs/volumes //hpacucli-9.40-12.0.vib

    Now run it:

    ~ # cd/opt/hp/hpacucli/bin

    / opt/HP/hpacucli/bin # . / hpacucli

    HP Array Configuration Utility CLI 9.40.12.0

    Detection of controllers... Fact.

    Type 'help' for a list of supported commands.

    Type "exit" to close the console.

    => ctrl all diag file=/tmp/my_ADUreport.zip ris = on = on zip xml = on

    Generation of diagnostic report... done

    -Online output

    / opt/HP/hpacucli/bin #.

    my_ADUreport.zip in / tmp can now be downloaded from the host...

    It could be that useful...

    / Rubeck

  • How to divide the Dates

    Hi all...

    Here, I use the following scripts...

    create table a10 (eno number, date f, date t, number of sal)

    INSERT IN A10 (ENO, F, T, SAL) VALUES)

    1, TO_Date (1 July 2013 12:00:00 AM ',' DD/MM/YYYY HH: mi: SS AM'), TO_Date (June 30, 2014 12:00 ',' DD/MM/YYYY HH: mi: SS AM')

    (100);

    INSERT IN A10 (ENO, F, T, SAL) VALUES)

    1, TO_Date (May 1, 2013 12:00:00 AM ',' DD/MM/YYYY HH: mi: SS AM'), TO_Date (April 30, 2014 12:00 ',' DD/MM/YYYY HH: mi: SS AM')

    (200);

    COMMIT;

    entry:

    ENO      F             T                SAL

    07/01/2013 2014/06/30 100 1

    1 05/01/2013 30/04/2014 200

    Expected results:

    ENO FTSAL

    1 05/01/2013 2013/06/30 200

    1 30/04/2014 300 07/01/2013

    1 05/01/2014 2014/06/30 100

    I'm little bit confused how to divide the dates here... Any help is appreciated.

    Thank you all

    Stéphane

    Hello

    Always tell what version of Oracle you are using, especially if it's so old.

    In Oracle 10 (or 9, by the way) you can do this way:

    WITH cntr AS

    (

    SELECT LEVEL AS n

    OF the double

    CONNECT BY LEVEL<=>

    )

    got_change_date AS

    (

    SELECT d.eno

    C.n

    WHEN 1 THEN f

    ANOTHER t + 1

    END AS change_date

    C.n

    WHEN 1 THEN 1

    OF ANOTHER-1

    END as mul

    sal

    BY a10 d

    CROSS JOIN cntr c

    -WHERE... - If you need any filtering, put it here

    )

    got_total_sal AS

    (

    SELECT eno

    change_date f

    Advance (change_date) OVER (PARTITION BY eno

    ORDER BY change_date

    ) - 1 AS t

    SUM (sal * mul) over (PARTITION BY eno

    ORDER BY change_date

    ) AS total_sal

    OF got_change_date

    )

    SELECT *.

    OF got_total_sal

    WHERE t IS NOT NULL

    ORDER BY eno, f

    ;

  • How to access the data of all users of a page?

    Hi all, I'm new to APEX and have a query.

    I have installed APEX on my local machine, create a workspace and added a few users to roles.

    I'm creating an application, similar to a library application, where I have a table that stores information of books (BOOK_ID, BOOK_NAME, etc.). I would like to create another BOOK_USER table with two columns BOOK_ID and USER_ID. BOOK_ID refers to the BOOKS table and I want to USER_ID to refer to the table that stores the information of the users of the workspace I use. Data entry would be a page that has two LOVs, one for the name of book (using BOOK_ID as value) and another for the user name (USER_ID, or another field APEX uses to store the ID of the user). I can do in APEX? I found ways to access and authenticate a user to a page, but how to get the data of all users in the workspace? In other words, how to get all the usernames in a LOV?

    As I am new to APEX, I would appreciate if anyone can guide me through the steps, or posting links to the tutorial, etc.

    I think you can do this by querying APEX_WORKSPACE_GROUP_USERS.

  • How to read the data of BLOB and save to the file system

    Hi friends.

    I have called DEMO table there image stored as a BLOB. now my requirement is to know how to read the data of BLOB and saved in the file system. is there a procedure
    to read the blob object and stored in the file system. pls suggest me with an example.
    Thank you

    HI - don't know what version you have, but have a read through this:

    http://www.Oracle-base.com/articles/9i/ExportBlob9i.php

    Hoek link is to import the blobs in the db, it is export, to a file.

  • How to display the Date Predefault time

    Hi friends,

    How to display the date in the field to date through sctipting by default I have a requirementy to display the date field as the next day's date with timestamp from 09:00 (15/02/2010-09:00) data type as the field & column is UTC_datetime.please help I get.


    Siebel bee

    Take a look at the function today(), TimeStamp() and ToChar()

    You should be able todo with something similar to this:

    Expr: "ToChar (TimeStamp (), 'MM') + ' / ' + ToChar (TimeStamp (), 'DD') + ' / ' + ToChar (TimeStamp (), 'YYYY') + ' ' + ToChar (TimeStamp (+(1/24), 'HH')) + ': 00:00.

    as a value before failure.

  • Anyone know how to check the date of warranty until when?

    Anyone know how to check the date of warranty until when?

    https://checkcoverage.Apple.com/Jo/en/;JSESSIONID=9pJ0X9pFPJtNg3c44yDGCvk9pVpt5l QSgn4B60y4Skv1WfmnqMkF!-1840326800

  • How to find the date item was my favorites on Mozilla Firefox

    on system moot bookmark how to find the date of the bookmark?

    In bookmarks menu select organize bookmarks to open the bookmarks library. In the bookmarks library, click views, and then display the columns and then added. This will display a column showing when a bookmark has been added.

  • How to set the date and time on my HP Officejet pro 8600 more?

    How to set the date and time on my HP officejet pro 8600 more?  It just on a printed journal Jan-oo-oo fax shows 00:00 AM.  There are no instructions on how to change this.  I need proof that I sent a fax to a certain date and time.  Help, please.  Thank you

    Hello

    Below are the steps to set the Date and time for your device:

    1. On the Control Panel, press the right arrow key ( ), press Setup ( ).

  • Camileo S20 - How to display the date and time

    Hi, all. I got as Christmas present the Camileo S20, and I am not able to view the date and time in the video. In the manual is no reference on this subject, only how to set the date and time. But what is the intention to set the date and time in the camera, if it is not possible to display video?

    Hello

    Have you checked the user manual of your TV cam?

    If it of possible to display the data and the time you can find in your user manual how to do this. It always interesting to read ;) s

  • How to reset the data counter without resetting the phone

    How to reset the data counter each month so that I can control my data counter with our reset the phone (or) without using factory data reset.

    Thanks for the reply much appreciated.

    Parameters

    Data Manager

    Press the lower left key

    Reset the data counter

  • How to save the data in table 1 d to Excel in continuous

    Mr President.

    How to save the data in table 1 d to Excel at all times, so that all the data of the first scan must be placed first thought and all the data from the second analysis must be placed on the second Board and continue on the street...

    Sy@m...

    Hi Sy@m

    Here is a vi that might give you a few ideas to try:

  • How to read the date and time of a file by labview information

    How to read the date and time of a file by labview information? for example, time created and updated time.

    The similar question had already spoken here (this is the old thread but still seems topical):

    http://forums.NI.com/T5/LabVIEW/file-date-created/TD-p/109836

Maybe you are looking for

  • can not turn on icloud drive on Mac

    I'm turning in icloud drive on my devices. He succeeded on my PC and iPhone (photo below showing all my folders sync to the iphone). but the icloud drive folder will not be displayed only on my mac (see pictures for more details). What can I do?

  • iPod classic is locked permanently and will not restart or reset.

    I had my iPod Classic (160GB) for about six years. I received as a Christmas gift in 2010. For the last two days, the "lock" symbol was flicker on and out, even when the switch is moved to the off position. I went to put it on today and it wouldn't r

  • Qosmio F60 - whenever it starts, says it's the first use

    My laptop has just got back from repair (they replaced the hard drive). Now whenever I turn it on or restart it, it says Windows configures the computer for first use. Once the Panel opens with "how to customize your computer. In addition, a small wi

  • HP Envy 4500: failure to print

    The printer is out of warranty, but less than two years. I just replaced both ink cartridges, using HP ones. The alignment test was OK, but the printer now prints in color, only not in black. It was working fine last time I used it before replacing t

  • Multi-language app.

    Hello. I'm very very new development Playbook. I have a simple question: is it possible to know what is the language of the user? How can I make an multilingual app? Thank you very much.