开发者

Exact match with sql like and the bind

I have a bind in the SQL query

SELECT * FROM users WHERE name LIKE '%?%'

the bind s开发者_开发知识库et the ?.

Now, if i want to search with like method everything work but if, without change the sql, i want to search the exact match i dont now how to do.

I tried some regexp int the textbox es: _jon \jon\ [jon] and some others but nothing work properly.

Any ideas?


Change your query to

select * from users where name like '?'

If you want to do a wildcard match, put the wildcards as part of the string that you're binding to the variable. If you don't want to do a wildcard match, then don't.

Note that like and = have the same performance except when your wildcard character is first in the string (for example, '%bob') as in that case the query optimizer can't use indexes as well to find the row(s) that you're looking for.


you can't search an exact match if the sql contains % symbols, as they are wildcards. you'll need to change the sql to

select * from users where name = '?'

for an exact match

(you can also use select * from users where name like '?' but that's more inefficient)


What is keeping you from changing the SQL?

The Like condition is for 'similar' matches, while the '=' is for exact matches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜