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: Previous Month function

Re: Previous Month function

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Wed, 18 Aug 1999 11:44:51 GMT
Message-ID: <37bb9c19.175508247@newshost.us.oracle.com>


A copy of this was sent to john bruin <jbruin_at_tssc.co.nz> (if that email address didn't require changing) On Wed, 18 Aug 1999 13:00:42 +1200, you wrote:

>Does anyone know if there is a function to select records for the
>previous month. In the past we have run a query on the 1st day of the
>month and selected for the previous 31 days ("sydate -31") which is OK
>but requires sorting/deletion of unwanted records for the months that
>have 30 days or less.
>
>Any help appreciated,
>John

select * from T
where DATE_COLUMN between trunc( add_months(sysdate,-1),'month') AND

                          last_day( trunc( add_months(sysdate,-1),'month') ) 
/

gets last months data and will use an index on DATE_COLUMN if present.

--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Wed Aug 18 1999 - 06:44:51 CDT

Original text of this message

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