Reputation: 619
I m little bugged with Oracle
That my SQL below
select * from orders where
trunc(ordered_date)
between
to_date('01-JAN-12')
and
to_date('07-JAN-12')
Ordered_date is DATE datatype
Is it giving the below error.
Error starting at line 1 in command:
select * from orders
where
trunc(ordered_date)
between
to_date('01-JAN-12')
and
to_date('07-JAN-12')
Error report:
SQL Error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
01841. 00000 - "(full) year must be between -4713 and +9999, and not be 0"
*Cause: Illegal year entered
*Action: Input year in the specified range
I'm confused what is causing this error in mu code.
Any inputs would be great.
Thanks !!!
Upvotes: 1
Views: 2554
Reputation: 2030
Maybe you should convert both the dates, i.e DB date and the 2 input dates, into the same format, like this
SELECT *
FROM ORDERS O
WHERE TO_DATE(TO_CHAR(O.ORDERED_DATE, 'DD-MON-YY'), 'DD-MON-YY') BETWEEN
TO_DATE('01-JAN-12', 'DD-MON-YY') AND
TO_DATE('07-JAN-12', 'DD-MON-YY')
Hope it helps
Upvotes: 0
Reputation: 60262
If you're really using date literals, you can use this syntax instead:
select * from orders where
trunc(ordered_date)
between
date '2012-01-01'
and
date '2012-01-07'
Upvotes: 0
Reputation:
You have to specified the date format.
Add a parameter to to_date function :
to_date('01-JAN-12', 'DD-Mon-YY')
Hope it's helps.
Regards.
Upvotes: 1