ITPub博客

首页 > 数据库 > Oracle > ibatis模糊查询

ibatis模糊查询

Oracle 作者:othering 时间:2014-02-11 23:28:58 0 删除 编辑

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# + '%'
<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/21628735/viewspace-1116407/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2009-05-12