• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use underscore as literal not as wild char

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello dears,


I'm using oracle and need to use the underscore as literal not as wild char in qurery

I found on the internet something like this

SELECT SAMPLE_NAME FROM SAMPLES WHERE SAMPLE_NAME LIKE 'ABC\_XYZ' ESCAPE '\'

and if there is SAMPLE_NAME equales ABC_XYZ it will be feached


but in my case the string that i compare to is variable(entred by user)

select SAMPLE_NAME FROM SAMPLES WHERE SAMPLE_NAME LIKE ?

Is there any way to disable using '_' as wildchar in general in queris???

or the only solution is to process user input before using it in LIKE statement !

thanks in advance
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is still the way to do it. You can use String's replaceAll method in Java to convert the string to have the escape character before submitting.

Your real example probably looks like "like % " + userInput + "%". If it doesn't have the % wildcard, you could just use "field = userInput" and be done with it.

Obviously, you still use a PreparedStatement here. I'm spelling out the input to make it clearer.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sure i read about something in oracle to allow you to set your wildcards, in an old thread.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic