zoukankan      html  css  js  c++  java
  • 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# + '%'



      关于数据库字符串连接符简单列举我使用过的一些数据库如下:

     

    OracleSQLServerMysqlDB2
    || 或 CONCAT()+CONCAT()|| 或CONCAT()

  • 相关阅读:
    三个问题
    2014-7
    2014-5
    2014-2
    2014-1
    2013-11
    mysql中对表操作----为所有列插入数据
    Redis做消息队列
    收集Nginx-access,Nginx-error日志
    .Nginx安装filebeat收集日志:
  • 原文地址:https://www.cnblogs.com/wuxiang/p/3700648.html
Copyright © 2011-2022 走看看