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: Problem with query with dates in where clause

Re: Problem with query with dates in where clause

From: Casey Dyke <cdyke_at_homenetwork.com.au>
Date: Tue, 20 Jun 2000 16:30:57 +1000
Message-Id: <10533.109814@fatcity.com>


This is a multi-part message in MIME format.

--------------078774F956C130798F1C9339
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Shiva,

Had to do this a lot in a former role. Something like this may help.

set echo off verify off

accept sdt prompt 'Enter Starting Date (dd/mm/yyyy) ==>> ' accept edt prompt 'Enter Ending Date (dd/mm/yyyy) ==>> '

select emp_id
from emp
where hire_dt >= to_date('&sdt'||' 00:00:00', 'dd/mm/yyyy hh24:mi:ss') and hire_dt <= to_date('&edt'||' 23:59:59','dd/mm/yyyy hh24:mi:ss') and sackemnowflag = 'Y';

HTH, Cheers,

Casey ...

dgoulet_at_vicr.com wrote:

> Shiva,
>
> Yours is a VERY old problem with Oracle and dates. Basically an Oracle data
> field includes a time variable. In many cases this really stinks (like yours).
> What you need to do to keep the use of an index on this one is change the where
> clause to:
>
> where hiredate between to_date('19-JUN-00') and to_date('20-JUN-00')
>
> This will give you consistent results. Your original query gets the time added
> to it at whatever time it is when executed.
>
> ____________________Reply Separator____________________
> Author: "B Siva Shankar" <bsshankar_at_chennai.tcs.co.in>
> Date: 6/19/00 12:24 AM
>
> Hi List,
>
> We have problems in queries which have dates in where clause.
>
> Select * from Emp
> where hiredate = sysdate;
>
> Select * from Emp
> where hiredate = '19-JUN-00';
>
> The above two queries are not returning any records even though there are some
> records in the table satisfying the criteria.
>
> Can someone explain why it is so. We don't want to use to_char while comparing.
>
> Thanks in advance,
> Shiva.
>
> --
> Author: B Siva Shankar
> INET: bsshankar_at_chennai.tcs.co.in
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> 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).
> --
> Author:
> INET: dgoulet_at_vicr.com
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> 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).

--------------078774F956C130798F1C9339
Content-Type: text/x-vcard; charset=us-ascii;  name="cdyke.vcf"

Content-Transfer-Encoding: 7bit
Content-Description: Card for Casey Dyke
Content-Disposition: attachment;

 filename="cdyke.vcf"

begin:vcard
n:Dyke;Casey

tel;pager:(022) 9436 9290
tel;home:61 2 9948 1487
tel;work:61 2 9005 1021

x-mozilla-html:FALSE
url:www.realsurf.com
org:At Home Network Australia;IT-Ops
adr:;;100 Harris Street;Pyrmont;NSW;2042;Australia
version:2.1
email;internet:cdyke_at_homenetwork.com.au
title:Senior DBA Received on Tue Jun 20 2000 - 01:30:57 CDT

Original text of this message

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