Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
02-03-2008, 01:22 PM #1
- Join Date
- Feb 2008
- Thanked 0 Times in 0 Posts
How to disable the wildcards(% and _)
I have a search option in my web page. My input from UI is any thing like alphabets,numbers, special chars(%$#_). My query is select * from vendor where vendor_name like 'vendorname%'; The condition input is(vendorname) anything. Based on the input i have to display the results. My query is working fine for all conditions except the input % and _. B'coz, these values are wild cards in Database. How can I send as a String in database if the values are %_. I'm using Java, J2ee and DB2. Please help me.
02-05-2008, 05:16 PM #2
I don't know for certain whether this applies to regular syntax (as opposed to advanced syntax) but it looks like you probably want to follow this general form:
Wildcards ("%", "_")
Just as the LIKE operator, advanced syntax uses "%" and "_" as wildcards. The percent sign "%" is a wildcard character used to represent any number of arbitrary characters. The underscore "_" is a wildcard character used to represent a single arbitrary character. If you want a wildcard character to be treated as a regular character, you need to do the following:
1. Precede the wildcard character with an escape character
2. Add an ESCAPE clause after EACH term where you use the escape character
/Book[contains-text-db2 (@Title, " 'Usage of underscore !_ in query' ESCAPE '!' ")=1] SORTBY (score-db2 (@Title, " 'Usage of underscore !_ in query' ESCAPE '!' "))
In this example, an exclamation mark "!" is used as an escape character before the underscore.
/Book[contains-text-db2 (@Title, " 'Usage of underscore !_ in query' ESCAPE '!' | 'Yahoo! For Dummies' | 'Usage of underscore !_ on Yahoo!!' ESCAPE '!' | 'War and Peace' ")=1]
Note that an ESCAPE clause must be added after every term in your text search string where you escape wildcards, even if the escape character is the same in all the terms.