Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: CASE in PL/SQL

RE: CASE in PL/SQL

From: Chelur, Jayadas {PBSG} <jayadas.chelur_at_pepsi.com>
Date: Thu, 03 Jul 2003 06:01:15 -0800
Message-ID: <F001.005C336A.20030703060115@fatcity.com>


Surendra,  

The following query lists 12 months along with the actual year and quarter as well as the financial year and financial quarter ... probably you can modify this query to use in your cursor ...  

SELECT  CUR_DATE,
        CUR_YEAR,
        CUR_QTR,
        FIN_QTR,
        LEAST(0,SIGN(CUR_QTR-FIN_QTR))+CUR_YEAR FIN_YEAR
FROM    (
        SELECT  ADD_MONTHS(TO_DATE('01-JAN-2003','DD-MON-YYYY'),ROWNUM-1)
CUR_DATE,   TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('01-JAN-2003','DD-MON-YYYY'),ROWNUM-1), 'YYYY')) CUR_YEAR,   TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('01-JAN-2003','DD-MON-YYYY'),ROWNUM-1), 'Q')) CUR_QTR,   TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('01-JAN-2003','DD-MON-YYYY'),ROWNUM-1+6 ),'Q')) FIN_QTR
        FROM    ALL_OBJECTS
        WHERE   ROWNUM < 13
        );

HTH ...   Regards,
Jayadas

-----Original Message-----
[mailto:Surendra.Tirumala_at_mail.state.ky.us] Sent: Wednesday, July 02, 2003 6:11 PM
To: Multiple recipients of list ORACLE-L

I am already using it that way, but giving that condition in cursor is not possible.
Thanks for your help.
Surendra

-----Original Message-----
Sent: Wednesday, July 02, 2003 5:01 PM
To: Multiple recipients of list ORACLE-L

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 ...

-----Original Message-----
[ mailto:Surendra.Tirumala_at_mail.state.ky.us <mailto:Surendra.Tirumala_at_mail.state.ky.us> ] Sent: Wednesday, July 02, 2003 4:06 PM
To: Multiple recipients of list ORACLE-L

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, 
> 
> I am trying to find quarter number from a given date . Here is the 
> description 
> 
>  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. 
>  July -Sep  -> 1st Quarter 
>  Oct  -Dec  -> 2nd Quarter 
>  Jan  -Mar  -> 3rd Quarter 
>  Apr  -Jun  -> 4th Quarter 
> 
> I got this done using the following Select 
> 
> select decode(to_char(add_months(sysdate,9),'Q'), 
>                                          '1','3', 
> '2','4', 
>          '3','1', 
>          '4','2', 
>               '') 
> 
> Decode function is used to change calender quarter to our Quarter. 
> 
> But I am unable to find the Year for that quarter. 
> I was using Case statement to solve my problem,as below 
> 
>  Select case when decode(to_char(add_months(sysdate,9),'Q'), 
>                                          '1','3', 
> '2','4', 
>          '3','1', 
>          '4','2', 
>               '') < 3 
>              then to_number(to_char(main_rec.termination_date,''YYYY''))+1

>      else to_number(to_char(main_rec.termination_date,''YYYY'')) 
> 
> 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 
> accordingly. 
> 
> But,this works only in SQL, in Procedures, i cannot do this using CASE 
> Statement 

>
> Can anybody give some ideas on how to approach this?. I have to use this in
> 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 
> Cabinet for Workforce Development 
> Commonwealth of Kentucky 
> -- 
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
<http://www.orafaq.net>
> -- 
> Author: 
>   INET: Surendra.Tirumala_at_mail.state.ky.us 
> 
> Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
<http://www.fatcity.com>  
> San Diego, California        -- Mailing list and web hosting services 
> --------------------------------------------------------------------- 
> To REMOVE yourself from this mailing list, send an E-Mail message 
> to: ListGuru_at_fatcity.com (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: http://www.orafaq.net <http://www.orafaq.net>
--

Author: George Oneata
  INET: gxg_at_initora.ro

Fat City Network Services -- 858-538-5051 http://www.fatcity.com <http://www.fatcity.com>
San Diego, California -- Mailing list and web hosting services



To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (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: http://www.orafaq.net <http://www.orafaq.net>
--

Author:
  INET: Surendra.Tirumala_at_mail.state.ky.us

Fat City Network Services -- 858-538-5051 http://www.fatcity.com <http://www.fatcity.com>
San Diego, California -- Mailing list and web hosting services



To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (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: http://www.orafaq.net
--

Author: Chelur, Jayadas {PBSG}
  INET: jayadas.chelur_at_pepsi.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (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 Thu Jul 03 2003 - 09:01:15 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US