ju***@davidbevan.co.uk wrote:
I am running a query from a Java app via the IBM type 4 driver back to
MF DB2 and am getting a strange result.
Basically my statement is
SELECT BLAH WHERE NAME LIKE ?
...and I pass in "Fr%" expecting it to match with "Fred" but it doesnt.
...but if I pass in "Fr%%" then it does match "Fred".
Several other combinations - "Sa%%y" matching "Sally" but "Sa%y" NOT
matching "Sally" seem to suggest that the '%' is being treated as a
single char wild card and not a 1 to many wildcard?
Am I going mad or should "Fr%" match "Fred"?
Not sure about this, but I'd guess that using parameter markers and
SQL wildcards has different symantecs than straight SQL.
That is, a single percent '%' is probably being interpreted as a
literal percent sign, but '%%' is being interpreted as the wildcard
(similar to how you embed a escape single quote in a value, as in
select id from table where word = 'don''t')
So 'Fr%' would match 'Fr%', not 'Fra', 'Fre', 'Frx' etc.