Domanda

select flightdate from flight;
FLIGHTDATE

01-DEC-12 10.09.01.340000 AM
02-DEC-12 10.09.01.340000 AM
02-DEC-12 10.09.01.340000 AM
03-DEC-12 10.09.01.340000 AM
05-DEC-12 10.09.01.340000 AM
03-DEC-12 10.09.01.340000 AM
04-DEC-12 10.09.01.340000 AM
06-DEC-12 10.09.01.340000 AM

Now I want to get the flightdate > 03-DEC-12

I have written the query as

select flightdate from flight where flightdate>'03-DEC-12'

output:

03-DEC-12 10.09.01.340000 AM
05-DEC-12 10.09.01.340000 AM
03-DEC-12 10.09.01.340000 AM
04-DEC-12 10.09.01.340000 AM
06-DEC-12 10.09.01.340000 AM

I am even getting the 03-DEC-12

È stato utile?

Soluzione

You are getting events from the December 3rd because 03-DEC-12 gets interpreted as 2012-12-03T00:00:00 and an event 10 hours after midnight does match.

If you want events starting the following day, use

SELECT *
FROM flight 
WHERE FLIGHTDATE >= DATE '2012-12-04'
-- or FLIGHTDATE >= (DATE '2012-12-03') + 1

You could also truncate the datetime to a date using the TRUNC function, but this may make the query non-sargable:

SELECT *
FROM flight
WHERE TRUNC(FLIGHTDATE) > TO_DATE('03-DEC-12', 'DD-MON-YY')

Altri suggerimenti

  • Here your Flightdate column contains time stamp(03-DEC-12 10.09.01.340000).

  • In where clause you provided flightdate>'03-DEC-12'.

  • Oracle treated the date you supplied as flightdate>'03-DEC-12 00.00.00.000'

  • So when ever you deal with date its always better to use TO_DATE() function.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top