ibatis中使用like模糊查询


无效的方法:

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# + '%'

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM