Title: 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-----
From: Jamadagni, Rajendra [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 29, 2002 10:42 AM
To: 'Mercadante, Thomas F'; '[EMAIL PROTECTED]'
Subject: RE: Implicit Date conversion problem

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
where veas.ep_number = ea1.ep_number
  and ea1.est_dt between '20-Dec-02' and '01-Jan-03'

-- This DOES work ... returns all the right 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
where veas.ep_number = ea1.ep_number
--  and ea1.est_dt between '20-Dec-02' and '01-Jan-03'

Point to consider is that the "commented out where clause" is the same as the one used in the from clause query ... then why does it fail?

Tom: according to Oracle, when comparing a varchar2 to a date column, the string does get converted to a date ... 

The reason i am asking this I have to explain the developers on why this isn't working. They agree that explicit datatype conversion is a good idea but their managers want to know why ??

(yeah ... sure go ahead pity me ...)
Raj
______________________________________________________
Rajendra Jamadagni              MIS, ESPN Inc.
Rajendra dot Jamadagni at ESPN dot com
Any opinion expressed here is personal and doesn't reflect that of ESPN Inc.
QOTD: Any clod can have facts, but having an opinion is an art!

-----Original Message-----
From: Mercadante, Thomas F [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 29, 2002 10:35 AM
To: '[EMAIL PROTECTED]'
Cc: Jamadagni, Rajendra
Subject: RE: Implicit Date conversion problem


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
where veas.ep_number = ea1.ep_number
  and ea1.est_dt between between to_date('20-Dec-2002','dd-mon-yyyy') and to_date('01-Jan-2003' ,'dd-mon-yyyy')

Your selection was not working properly because you ended up comparing string values with string values.

example:  21-Dec-2002 is not between 20-Dec-2002 and 01-Jan-2003 using string comparison
                    (21 is greater than 20 and 01 both).

hope this helps.

Tom Mercadante
Oracle Certified Professional

Reply via email to