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

Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL retrieving last two months

Re: SQL retrieving last two months

From: ImPrecise <f_puhan_at_precise.com>
Date: Fri, 28 Jun 2002 10:15:29 -0400
Message-ID: <f_puhan-C7A562.10152928062002@vienna7.his.com>


Let me add that recently I had need to perform a similar function. I wound up using the DECODE and TO_CHAR functions. E.G.:

select
  decode(to_char(date_field,'MON'),'JAN','JAN',   decode(to_char(date_field,'MON'),'FEB','FEB',   ...
from
  table_with_date_field
/

I suspect you could, with a little imagination, arrive at something approximating

SELECT
  RECNO, DATE, TITLE
FROM
  table
WHERE
  decode(to_char(DATE,'MON') = '&month_to_query' /

In article <f_puhan-74C554.10075028062002_at_vienna7.his.com>,  ImPrecise <f_puhan_at_precise.com> wrote:

> Aha! You've added to the spec.
>
> Most likely you'll have to do this programmatically. Fetch the SYSDATE
> into a variable and then perform date arithmetic. You can use the TRUNC
> and ROUND functions to establish the beginning of the month(s) once you
> have done so.
>
> In article <afhnn2$nb$1_at_news.ost.eltele.no>,
> "Per Magne" <perman_at_online.no> wrote:
>
> > This only gives you the last 60 days.
> > I want to get each month separately.

-- 
The underscore character does not belong in my address. You know the drill...
***
Anyone sufficiently smart enough to configure and use USEnet for research should
be smart enough to Read The Freakin' Documentation!
Received on Fri Jun 28 2002 - 09:15:29 CDT

Original text of this message

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