aspose file tools
The moose likes JDBC and Relational Databases 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


Win a copy of Meteor in Action this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31769
    
192

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



[OCA 8 book] [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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31769
    
192

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

Joined: Dec 18, 2006
Posts: 225

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