Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Peculiar results from a simple looking query.
Sybrand Bakker wrote:
> On 24 Feb 2005 09:45:47 -0800, netspam_at_shic.co.uk (Steve H) wrote: > >
> > > I would recommend writing ordinary SQL > such as > select field from atable where field like 'Th%' > and of course read the manuals > and stop shouting 'BUG' at he first thing you don't understand > > Oracle != Sqlserver. > > > -- > Sybrand Bakker, Senior Oracle DBA
I spent several minutes trying to understand this myself, and didn't reply at first since I couldn't come with anything, other than a variation on the above advice to use more straightforward SQL (SUBSTR function instead of CAST).
Why *does* Oracle change the datatype of a column in the SELECT clause due to use of a function in the WHERE clause? Couldn't think of any other situation where this happens, nothing on Metalink except an oblique reference to this issue when migrating from SQL Server.
select dump(field) from atable where substr(field,1,2) = 'Th';
DUMP(FIELD)
select dump(field) from atable where cast(field as varchar2(2))='Th';
DUMP(FIELD)
However, the following is a possible work-around:
select field from atable
where cast(to_char(field) as varchar2(2)) = 'Th';
FIELD
-Mark Bole Received on Thu Feb 24 2005 - 14:04:06 CST