• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using wildcards literally in queries

 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to retrieve rows from an Oracle table which has values like "sp_bowl" or "asp_007" etc. My query is like
SELECT MYROW FROM MYTABLE WHERE MYCOLUMN LIKE ?
I'm using PreparedStatements, and passing Strings using preparedStatement.setString(1,"%"+myString+"%").
When the use enters "sp_" as the string to be passed to the query, I'm getting all rows which have "sp" in them, but not ones which have the UNDERSCORE character in them. How can I force the Underscore character to be treated literally and not as a wildcard ?
Any suggestions would be welcome.
Thanks.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
insert the Oracle escape character \ in your query:
select * from table where column1 like '%sp\_bowl'
this would find all values that end in "sp_bowl" literally.

Jamie
 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jamie. It worked :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic