By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,323 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,323 IT Pros & Developers. It's quick & easy.

working with dates in oracle

P: n/a
I need to write a query in oracle 8i that will allow me to select some
rows of date within a date range. In MSSQL I would do something like
"select f1,f2 from tablea where lastdate >= '01/01/2002'" . How do I
accomplish the same type of query in Oracle.
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
select f1,f2 from tablea where lastdate >=
to_date('01/01/2002','mm/dd/yyyy')
(assuming you mean month then day in your format.)
Jim

"UnixUser" <ra*********@pfshouston.com> wrote in message
news:a1**************************@posting.google.c om...
I need to write a query in oracle 8i that will allow me to select some
rows of date within a date range. In MSSQL I would do something like
"select f1,f2 from tablea where lastdate >= '01/01/2002'" . How do I
accomplish the same type of query in Oracle.

Jul 19 '05 #2

P: n/a

Originally posted by Kuljeet
ra*********@pfshouston.com (UnixUser) wrote in message
news:news:...
I need to write a query in oracle 8i that will allow me to

select some
rows of date within a date range. In MSSQL I would do something

like
"select f1,f2 from tablea where lastdate >= '01/01/2002'" . How

do I
accomplish the same type of query in Oracle.


try-->
select f1,f2 from tablea where to_char(lastdate,'DD/MM/YYYY') >=
'01/01/2002';

NO! See Jim Kennedy's answer for the correct approach. The above does
a string comparison, and will say that '02/01/1999' is greater than
'01/01/2002'!

--
Posted via http://dbforums.com
Jul 19 '05 #3

P: n/a
andrewst wrote:
Originally posted by Kuljeet
try-->
select f1,f2 from tablea where to_char(lastdate,'DD/MM/YYYY') >=
'01/01/2002';

NO! See Jim Kennedy's answer for the correct approach. The above does
a string comparison, and will say that '02/01/1999' is greater than
'01/01/2002'!


And it'll be much slower since you're applying the to_char() function
for each row in the table, instead of just applying the to_date()
function once.

Of course, the bigger problem is the accuracy, not the performance...

--
//-Walt
//
//
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.