Unix Technical Forum

Problem with 'like' compare

This is a discussion on Problem with 'like' compare within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Hi, I have a table with a VARCHAR2 field (Oracle 9i), and I'm trying to do a SELECT using ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-07-2008, 09:57 PM
ohaya
 
Posts: n/a
Default Problem with 'like' compare

Hi,

I have a table with a VARCHAR2 field (Oracle 9i), and I'm trying to do a
SELECT using a "where ... like ...", and am having a problem.


The field (myfield) in the records in the table contain a bunch of text,
and in the middle, there's something like:

"....SerialNumber: [0a]..."

"....SerialNumber: [0b]..."

etc.


My SELECT looks something like:

SELECT * from mytablename where lower(myfield) like
lower('%serialnumber: [ 0a]%')

is returning no rows.

If I change the SELECT to:

SELECT * from mytablename where lower(myfield) like
lower('%serialnumber:%')

the query does return rows (too many of them!!).

Can someone tell me what is wrong with this?

Thanks,
Jim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-07-2008, 09:57 PM
Andy Hassall
 
Posts: n/a
Default Re: Problem with 'like' compare

On Sat, 24 Jul 2004 13:42:50 -0400, ohaya <ohaya@cox.net> wrote:

>there's something like:
>
>"....SerialNumber: [0a]..."


No space after the [.
>
>My SELECT looks something like:
>
>SELECT * from mytablename where lower(myfield) like
>lower('%serialnumber: [ 0a]%')

^

A space after the [. They don't match.

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-07-2008, 09:57 PM
ohaya
 
Posts: n/a
Default Re: Problem with 'like' compare



Andy Hassall wrote:
>
> On Sat, 24 Jul 2004 13:42:50 -0400, ohaya <ohaya@cox.net> wrote:
>
> >there's something like:
> >
> >"....SerialNumber: [0a]..."

>
> No space after the [.
> >
> >My SELECT looks something like:
> >
> >SELECT * from mytablename where lower(myfield) like
> >lower('%serialnumber: [ 0a]%')

> ^
>
> A space after the [. They don't match.
>



Hi Andy,

I was trying to be careful when I typed my original post, but may've
messed up, but the fields in the records have a space/blank after the
colon and after the left brackets ("[ 0a]"), and in the WHERE in the
SELECT that I'm using, I'm putting spaces/blanks in both those places,
and am not getting any rows back.

What's puzzling is if I put a string up to and including the left
bracket in the WHERE, the query returns information. It's only if I try
to include the text/data past the "[" that the query fails.

Is it possible the lower() is messing up the "0a", or something like
that? I've tried using upper() instead, but same problem.

Jim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-07-2008, 09:57 PM
ohaya
 
Posts: n/a
Default Re: Problem with 'like' compare


> Hi Andy,
>
> I was trying to be careful when I typed my original post, but may've
> messed up, but the fields in the records have a space/blank after the
> colon and after the left brackets ("[ 0a]"), and in the WHERE in the
> SELECT that I'm using, I'm putting spaces/blanks in both those places,
> and am not getting any rows back.
>
> What's puzzling is if I put a string up to and including the left
> bracket in the WHERE, the query returns information. It's only if I try
> to include the text/data past the "[" that the query fails.
>
> Is it possible the lower() is messing up the "0a", or something like
> that? I've tried using upper() instead, but same problem.
>
> Jim



Hi,

Ok, I've figured it out. The field actually has the string something
like:

....SerialNumber: [ 0a]...

i.e., the info between the brackets is 6-characters, left-blank-filled.
I was looking at the info in View/Edit Contents in OEM, and you can't
see those 4 blanks, but when I did a query using SQLPlus, they showed up
...

Thanks,
Jim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com