aspose file tools*
The moose likes JDBC and the fly likes Issue on pattern matching in Oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Issue on pattern matching in Oracle" Watch "Issue on pattern matching in Oracle" New topic
Author

Issue on pattern matching in Oracle

Ravindranath Chowdary
Ranch Hand

Joined: Nov 08, 2006
Posts: 71
Hi friends,
I have a query to pick the details from test table as follows...

SELECT key FROM test WHERE key like 'ib_b';

on executing this query i am getting the following records

ib_b
ibbb
ibnb
ibhb
ib_b

I need to get only that matches 'ib_b' only. I think here Pattern matching happens.

Can anyone give an idea how to disable the pattern matching in Oracle.
I have so many of the web pages using this query. So, i need a generic solution for this.


Thanks,
Ravindra.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29241
    
139

Ravindra,
"like" is the operator for pattern matching. "=" is the operator for string comparison. The following query does what you want.



[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29241
    
139

Moving to our JDBC forum since this isn't Oracle specific.
Baseet Ahmed
Ranch Hand

Joined: Dec 18, 2006
Posts: 224
Ravindra,

You can use escape keyword of Oracle to avoid this kind of problem.
Use following query:
SELECT key FROM test WHERE key like 'ib$_b' escape '$';

Note that you can use any special character(insteadof $) for escaping pattern match.

Hope this helps.


***********************************
Tip: Sincerity is mother of all acheivements.
***********************************
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue on pattern matching in Oracle
 
Similar Threads
SQL question
Seemingly simple EJB-QL question
javax. servlet. include. path_info not set.
comparison between expected and Actual value
Error accessing RSS links using Oracle