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: Strange Date behaviour

Re: Strange Date behaviour

From: Stephan Born <stephan.born_at_bNrOaSiPnAfMorce.com>
Date: Wed, 02 Apr 2003 09:25:31 +0200
Message-ID: <c93e6b.s5d.ln@gatekeeper.solutions.beusen.de>

andrewst wrote:
[snip]
>
> Try one of these instead:
>
> select * from OUR_WORK where
> trunc(WORK_DATE)=TO_DATE('31-MAR-2003','DD-MON-YYYY'); -- uses TRUNC
> function to ignore the time in WORK_DATE
>
> select * from OUR_WORK where WORK_DATE >=
> TO_DATE('31-MAR-2003','DD-MON-YYYY') and WORK_DATE <
> TO_DATE('01-APR-2003','DD-MON-YYYY');
>
> The second version, while more verbose, allows use of an index on
> WORK_DATE.
If you don't like the more verbose version, but yet want to use an index, you can create a 'function based index' ( since Oracle 8i if I recall correctly ).

CREATE INDEX work_trunc_date_idx ON OUR_WORK( trunc( WORK_DATE ) );

Now the first example should use an index as well.

Regards, Stephan

-- 
---------------------------------------------------------------
Dipl.-Inf. (FH) Stephan Born        | BRAIN FORCE SOFTWARE GmbH
                                     | Landsberger Allee 366
eMail: delete the capital letters   | 12681 Berlin
eMail: entferne die Grossbuchstaben | Germany
---------------------------------------------------------------
          PGP-Key verfügbar          |    PGP-Key available
---------------------------------------------------------------
Received on Wed Apr 02 2003 - 01:25:31 CST

Original text of this message

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