Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Implicit Date conversion problem
Tom,
If the string matches the NLS_DATE_FORMAT, Oracle will convert it to a date.
Try this:
create table d( d date );
alter session set nls_date_format = 'dd-mon-yy';
insert into d values('21-dec-02'); insert into d values('22-dec-02'); insert into d values('23-dec-02'); insert into d values('24-dec-02');
commit;
select *
from d
where d.d between '22-dec-02' and '23-dec-02'
/
Jared
"Mercadante, Thomas F" <NDATFM_at_labor.state.ny.us>
Sent by: root_at_fatcity.com
10/29/2002 07:54 AM
Please respond to ORACLE-L
To: Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com> cc: Subject: RE: Implicit Date conversion problem
Raj,
you said:
"according to Oracle, when comparing a varchar2 to a date column, the string does get converted to a date ... "
This has got to be wrong. If you compare a varchar2 column with a number, Oracle try's to convert the varchar2 to a number, and we end up with an "invalid number" error. Oracle has not choice but to attempt to convert a database column to a literal - it can *never* go in the other direction because it cannot make the correct assumption. At least I would not try and provide that service.
I would explain to the developers and the managers that this is the way it works. And it will always work correctly if they do explicit date conversion in their Sql. Once they begin coding this correctly, they will always be happy - it will always work consistently.
The manuals have been known to be wrong in the past, and if you and they have found the above quote in a manual, it is wrong. At least I have *never* seen Oracle act like this.
Hope this helps.
Tom Mercadante
Oracle Certified Professional
-----Original Message-----
Sent: Tuesday, October 29, 2002 10:42 AM
To: 'Mercadante, Thomas F'; 'ORACLE-L_at_fatcity.com'
Well,
Let me point out one thing .... following is the original query ...
-- this returns no rows ...
select ea1.ep_number, ea1.est_dt, veas.est_dt
from (select a.ep_number, ea.est_dt
from v_episode_avail_summary_break a, episode_airings ea where a.ep_number = ea.ep_number and ea.est_dt between '20-Dec-02' and '01-Jan-03' group by a.ep_number, ea.est_dt) veas, episode_airings ea1
from v_episode_avail_summary_break a, episode_airings ea where a.ep_number = ea.ep_number and ea.est_dt between '20-Dec-02' and '01-Jan-03' group by a.ep_number, ea.est_dt) veas, episode_airings ea1
Raj,
you are forgetting how dates are stored internally vs. how they are
displayed by sqlplus.
change your first query to:
select ea1.ep_number, ea1.est_dt, veas.est_dt
from (select a.ep_number, ea.est_dt
from v_episode_avail_summary_break a, episode_airings ea where a.ep_number = ea.ep_number and ea.est_dt between to_date('20-Dec-2002','dd-mon-yyyy') and to_date('01-Jan-2003' ,'dd-mon-yyyy') group by a.ep_number, ea.est_dt) veas, episode_airings ea1
(21 is greater than 20 and 01 both).hope this helps.
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author:
INET: Jared.Still_at_radisys.com
Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services ---------------------------------------------------------------------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). Received on Tue Oct 29 2002 - 11:59:14 CST
![]() |
![]() |