zoukankan      html  css  js  c++  java
  • mybatis中的模糊查询,Oracle和MySQL中的concat

    MySQL数据库,利用concat函数即可,MySQL不用能||连接字符串

    mapper.xml

      select * from tb_content_category where title like concat('%',#{paramMap.TITLE, jdbcType=VARCHAR},'%')

    Oracle数据库,利用concat函数或者||,Oracle数据库利用concat函数时,需要嵌套concat,因为Oracle的concat函数每次只能连接两个字符串

    mapper.xml

      select user_account, full_name from tm_user where full_name like '%'||#{paramMap.TITLE, jdbcType=VARCHAR}||'%'
    或者
      select user_account, full_name from tm_user where full_name like concat(concat('%',#{paramMap.TITLE, jdbcType=VARCHAR}),'%')

    或者直接在传入参数时,将需要模糊查询的参数前后加上%

  • 相关阅读:
    08-01集合运算
    07-03成员运算符
    07-02集合
    07-01结构与封装
    06-01字符串格式化.md
    06-03线性结构与切片
    06-02字符串与bytes
    05-02命名元组
    05-01元组
    04-01列表与常用操作
  • 原文地址:https://www.cnblogs.com/alphajuns/p/12689641.html
Copyright © 2011-2022 走看看