RE: sql question

  • From: "Channa, Santhosh" <Santhosh.Channa@xxxxxxxxxxxx>
  • To: joan.hsieh@xxxxxxxxx, oracle_l <ORACLE-L@xxxxxxxxxxxxx>
  • Date: Tue, 5 Jan 2010 14:35:24 -0500

You may try this for Year.

select decode(to_char(sysdate,'mm'),12,to_char(sysdate,'yyyy')-1,
to_char(sysdate,'yyyy')) year from dual

Regards,
Santhosh Channa

P Consider the environment. Please don't print this e-mail unless you
really need to.


-----Original Message-----
From: Joan Hsieh [mailto:joan.hsieh@xxxxxxxxx] 
Sent: Tuesday, January 05, 2010 2:23 PM
To: oracle_l
Subject: sql question

Hi,

I am trying to modify a query with where clause like '&&year%%month%'to 
retrieve all the data by each month of the year.  I have managed this 
query to set up automatically run on the 15th of the month without any 
problem until it turned the year of 2010.

I used select substr(add_months(sysdate,-1),5,2) from dual to collect 
the month.
and select substr(sysdate,1,4) from dual to get the year.

The problem is I can't get the data on this month cause I will generate 
the date like '201012%'.

Do you know how to handle this? Using if statement? if the month is 12, 
then the year should be -1? I am not sure how to accomplish this.

Thanks,

Joan

--
//www.freelists.org/webpage/oracle-l
--
//www.freelists.org/webpage/oracle-l


Other related posts: