Home » SQL & PL/SQL » SQL & PL/SQL » Need help with proc
Need help with proc [message #18052] Tue, 08 February 2005 11:28 Go to next message
VJ
Messages: 24
Registered: June 2002
Junior Member
hello,
can any one help me with this proc please...
want to write a proc that will take 2 date cols as parameters
startdate, enddate and it should display the output as below ...

exec callproc('01-nov-2004','01-feb-2005');
then it should display

nov2004
dec2004
jan2005
feb2005

Thanks a ton in advance.. Its really urgent...

-VJ
Re: Need help with proc [message #18054 is a reply to message #18052] Tue, 08 February 2005 11:46 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Pass those parameters in as DATEs, not strings. You can use any table with enough rows in place of all_objects, or a pipelined function.

sql>create or replace procedure p_gen_months
  2    (p_start in date, p_end in date, p_rc out sys_refcursor)
  3  is
  4  begin
  5    open p_rc for
  6      select to_char(add_months(trunc(p_start, 'mm'), rownum - 1), 'Monyyyy') dt
  7        from all_objects
  8       where rownum <= months_between(trunc(p_end, 'mm'), trunc(p_start, 'mm')) + 1;
  9  end;
 10  /
 
Procedure created.
 
sql>var rc refcursor
sql>exec p_gen_months(to_date('11/01/2004', 'mm/dd/yyyy'), to_date('02/01/2005', 'mm/dd/yyyy'), :rc)
 
PL/SQL procedure successfully completed.
 
sql>print rc
 
DT
-------
Nov2004
Dec2004
Jan2005
Feb2005
 
4 rows selected.
Previous Topic: SLQ ORACLE LINK SERVER
Next Topic: Interview qs
Goto Forum:
  


Current Time: Fri Sep 27 06:19:43 CDT 2024