Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching oracle database using a "contains" query instead of an "exact match" query

I need to search my database which contains user information table. I know to get the result by searching with the query like the following

String query;
StringBuilder sb=new StringBuilder(1024);
sb.append("select * from userinfo where uname=").append(key);
query=sb.toString();

But what I need to do is.

  • If the key is abc
  • Then I need to search for all data In the database which having the value abc
  • For example
  • My database contains the data abc, aba, gjabc ,abcxyz,hjjabcxyz
  • Then I need to retrieve the values abc, gjabc, abcxyz, hjjabcxyz
  • Because all above values contains abc in common.

How can I achieve this?

like image 733
James Avatar asked Nov 30 '25 16:11

James


1 Answers

If you are using pure SQL you should use like surrounded with "%". Your query will then return all rows where uname contains "abc". Your query needs to look like this:

select * from userinfo where uname like '%key%'
like image 61
Magnilex Avatar answered Dec 02 '25 04:12

Magnilex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!