Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to disable the wildcards(% and _)

    Hi Friends,
    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.
    Regards
    Kasi.

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    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

    Example A:

    /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.

    Example B:

    /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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •