?
Solved

Oracle datetime query question

Posted on 2009-04-06
2
Medium Priority
?
827 Views
Last Modified: 2013-12-19
A junior question: I have some records with the saved_date filed: 03/04/2009, but when I run below query, no result displayed:
select * from table_name where saved_date = to_date('03/04/2009','mm/dd/yyyy')

When I changed to:
select * from table_name where saved_date >= to_date('03/04/2009','mm/dd/yyyy')

Then the three records of that day is shown. Could anyone let me know why the second ">=" query only returns the record of particular date instead of all the records after that date and how I could get the date query for a particular date?

Thanks.
0
Comment
Question by:heyday2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Assisted Solution

by:lwadwell
lwadwell earned 800 total points
ID: 24083468
Hi heyday2004,

there is possibly a time component in the field in the database - it is used in the comparison.  Hence the >= will return results as the TO_DATE() will return a date with a time of midnight a.m..  If you want to do an = test without time, try

select * from table_name where TRUNC(saved_date) = to_date('03/04/2009','mm/dd/yyyy')

lwadwell
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 1200 total points
ID: 24083881
the above query from lwadwell should work if you do have time in your value
but, if you have indexes on the saved_date column, I suggest writing the query like this instead.

select * from table_name where saved_date >= to_date('03/04/2009','mm/dd/yyyy') and saved_date < to_date('03/05/2009','mm/dd/yyyy')

using trunc on the column will negate the use of normal indexes
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This video shows how to recover a database from a user managed backup
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question