http://www.cnblogs.com/gaojing/archive/2013/01/04/2844932.html
无效的方法:
select * from table1 where name like '%#name#%'
两种有效的方法: 1) 使用$代替#。此种方法就是去掉了类型检查,使用字符串连接,不过可能会有sql注入风险。
select * from table1 where name like '%$name$%'
2) 使用连接符。不过不同的数据库中方式不同。
mysql:
select * from table1 where name like concat('%', #name#, '%')
oracle:
select * from table1 where name like '%' || #name# || '%'
sql server:
select * from table1 where name like '%' + #name# + '%'
本文介绍了在进行SQL模糊查询时的有效方法,包括使用特殊字符替换和连接符的方式,并针对MySQL、Oracle及SQL Server等不同数据库提供了具体的实现语句。
290

被折叠的 条评论
为什么被折叠?



