I am
already using it that way, but giving that condition in cursor is not
possible.
Thanks
for your help.
<FONT face=Arial color=#0000ff
size=2>Surendra
<FONT face=Tahoma
size=2>-----Original Message-----From: Jamadagni, Rajendra
[mailto:[EMAIL PROTECTED]Sent: Wednesday, July 02, 2003
5:01 PMTo: Multiple recipients of list ORACLE-LSubject:
RE: CASE in PL/SQL
just use the sql to assign value to your variable ... if you
really want my advise, make this a function or a procedure so you can call it
from where ever you want. As function can be completely written in pl/sql you
should be okay ...
- this is a procedure ... create or
replace PROCEDURE dbp_calc_fin_qtr
(pi_date in date, po_qtr number, po_year out number) <FONT
size=2>is
nCurrQtr pls_integer :=
to_number(to_char(pi_date,'Q'));
nFinQtr pls_integer := 0;
nFinYear pls_integer := to_number(to_char(pi_date,'YYYY'));
begin if nCurrQtr in (1,2)
then nFinQtr := nCurrQtr +
2; else <FONT
size=2> nFinQtr := nCurrQtr - 2; <FONT
size=2> nFinYear := nFinYear + 1; <FONT
size=2> end if; -- <FONT
size=2>end dbp_calc_fin_qtr; / <FONT
size=2>-- this functions returns following string ... <FONT
size=2>-- QQYYYY where QQ is financial qtr and YYYY is financial year
create or replace FUNCTION
dbp_calc_fin_qtryr (pi_date in date, po_qtr number, po_year out number)
return varchar2 is
nCurrQtr pls_integer :=
to_number(to_char(pi_date,'Q'));
nFinQtr pls_integer := 0;
nFinYear pls_integer := to_number(to_char(pi_date,'YYYY'));
begin if nCurrQtr in (1,2)
then nFinQtr := nCurrQtr +
2; else <FONT
size=2> nFinQtr := nCurrQtr - 2; <FONT
size=2> nFinYear := nFinYear + 1; <FONT
size=2> end if; -- <FONT
size=2> return (to_char(nFinQtr,'09') || to_char(nFinYear));
-- end
dbp_calc_fin_qtryr; / <FONT
size=2>Raj <FONT
size=2>--------------------------------------------------------------------------------
Rajendra dot Jamadagni at nospamespn dot com <FONT
size=2>All Views expressed in this email are strictly personal.
QOTD: Any clod can have facts, having an opinion is an art
!
-----Original Message----- From:
[EMAIL PROTECTED] [<A
href="mailto:[EMAIL PROTECTED]">mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 02, 2003 4:06 PM <FONT
size=2>To: Multiple recipients of list ORACLE-L <FONT
size=2>Subject: RE: CASE in PL/SQL
Hi George,
With this solution you can only find Quarter number. but I
also need Year of that quarter number.
when you say to_char(date,'Q'), it might go next year or stay
in current fiscal year depending on number of months
we add to the date.
Thanks, Surendra
-----Original Message----- Sent:
Wednesday, July 02, 2003 12:56 PM To: Multiple
recipients of list ORACLE-L
You don't need CASE. try :
to_char( date , 'Q')
George
> Hello ALL, > <FONT
size=2>> I am trying to find quarter number from a given date . Here is
the > description <FONT
size=2>> > Our Financial year runs from
July thru June. So, Given any date between > these
dates I need to find 3 quarters(9 months) from it. <FONT
size=2>> July -Sep -> 1st Quarter <FONT
size=2>> Oct -Dec -> 2nd Quarter <FONT
size=2>> Jan -Mar -> 3rd Quarter <FONT
size=2>> Apr -Jun -> 4th Quarter <FONT
size=2>> > I got this done using the following
Select > > select
decode(to_char(add_months(sysdate,9),'Q'), <FONT
size=2>>
'1','3', > '2','4', <FONT
size=2>>
'3','1', <FONT
size=2>>
'4','2', <FONT
size=2>>
'') > > Decode function
is used to change calender quarter to our Quarter. <FONT
size=2>> > But I am unable to find the Year for
that quarter. > I was using Case statement to solve
my problem,as below > <FONT
size=2>> Select case when
decode(to_char(add_months(sysdate,9),'Q'), <FONT
size=2>>
'1','3', > '2','4', <FONT
size=2>>
'3','1', <FONT
size=2>>
'4','2', <FONT
size=2>>
'') < 3 <FONT
size=2>>
then to_number(to_char(main_rec.termination_date,''YYYY''))+1 <FONT
size=2>> else
to_number(to_char(main_rec.termination_date,''YYYY'')) <FONT
size=2>> > P.S The reason for <3 condition
check in CASE Statement is, if a > sysdate+9months
falls in next Financial year , I need to change Year <FONT
size=2>> accordingly. > <FONT
size=2>> But,this works only in SQL, in Procedures, i cannot do this using
CASE > Statement <FONT
size=2>> > Can anybody give some ideas on how to
approach this?. I have to use this in <FONT
size=2>> a cursor (not in the body of my procedure, so condition
checking like "If > then else " after fetching year
is not possible) > > Any
help would be greatly appreciated. >
> Thanks, > Surendra
Tirumala > Database Administrator <FONT
size=2>> Cabinet for Workforce Development >
Commonwealth of Kentucky > -- <FONT
size=2>> Please see the official ORACLE-L FAQ: <A target=_blank
href="http://www.orafaq.net">http://www.orafaq.net <FONT
size=2>> -- > Author: <FONT
size=2>> INET: [EMAIL PROTECTED]
> > Fat City Network
Services -- 858-538-5051 <A target=_blank
href="http://www.fatcity.com">http://www.fatcity.com <FONT
size=2>> San Diego, California --
Mailing list and web hosting services >
> To REMOVE yourself from this mailing list, send an
E-Mail message > to: [EMAIL PROTECTED] (note
EXACT spelling of 'ListGuru') and in > the message
BODY, include a line containing: UNSUB ORACLE-L >
(or the name of mailing list you want to be removed from). You
may > also send the HELP command for other
information (like subscribing). >
- Please see the official ORACLE-L
FAQ: <A target=_blank
href="http://www.orafaq.net">http://www.orafaq.net <FONT
size=2>-- Author: George Oneata <FONT
size=2> INET: [EMAIL PROTECTED]
Fat City Network Services -- 858-538-5051 <A
target=_blank href="http://www.fatcity.com">http://www.fatcity.com
San Diego,
California -- Mailing list and web
hosting services <FONT
size=2>---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail
message to: [EMAIL PROTECTED] (note EXACT spelling
of 'ListGuru') and in the message BODY, include a line
containing: UNSUB ORACLE-L (or the name of mailing
list you want to be removed from). You may also
send the HELP command for other information (like subscribing).
- Please see the official ORACLE-L
FAQ: <A target=_blank
href="http://www.orafaq.net">http://www.orafaq.net <FONT
size=2>-- Author: INET:
[EMAIL PROTECTED]
Fat City Network Services -- 858-538-5051 <A
target=_blank href="http://www.fatcity.com">http://www.fatcity.com
San Diego,
California -- Mailing list and web
hosting services <FONT
size=2>---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail
message to: [EMAIL PROTECTED] (note EXACT spelling
of 'ListGuru') and in the message BODY, include a line
containing: UNSUB ORACLE-L (or the name of mailing
list you want to be removed from). You may also
send the HELP command for other information (like subscribing).
Received on Wed Jul 02 2003 - 16:26:33 CDT