If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > wildcards and ranges

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-22-04, 09:29
andrewhallam andrewhallam is offline
Registered User
 
Join Date: Dec 2003
Location: Nottingham, England
Posts: 52
wildcards and ranges

Running V8.1

I don't know if its somekind of installation DB2 setting or what but for some reason ranges don't work with the LIKE predicate.

For example

Have the following table :-
CREATE TABLE x
(
a vargraphic(10)
)

Insert 3 records :-
insert into x values ('a')
insert into x values ('aa')
insert into x values ('aaa')

Now retreive the data:

select * from x where a = 'a'
OK - returns 1 row.

select * from x where a like 'a'
OK - returns 1 row.

select * from x where a like 'a%'
OK - returns 3 rows.

select * from x where a like '[a]'
BAD - Should return 1 row!!!

select * from x where a like '[a]%'
BAD - Should return 3 rows!!!

Thanks in advance for any input on this.

Andy.
ahm@exel.co.uk
Reply With Quote
  #2 (permalink)  
Old 01-22-04, 09:48
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Andy,
DB2 has no construct for ranges while using LIKE.
It only has % = match zero or more characters and _ = match any single character. When you use LIKE '[a]' DB2 is looking for strings that are exactly = '[a]' . You will need to use some other construct to do ranges.

Andy
Reply With Quote
  #3 (permalink)  
Old 01-22-04, 10:04
andrewhallam andrewhallam is offline
Registered User
 
Join Date: Dec 2003
Location: Nottingham, England
Posts: 52
Really ?

[] is ANSI standard with wildcards.

I would have thought DB2 support this method.

Ohh well - have to do somekind of work around...

thanks.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On