MyBatis中Like语句使用方式

> Oracle

SELECT 
* 
FROM 
user 
WHERE 
name LIKE CONCAT('%',#{name},'%') 
或 
SELECT 
* 
FROM 
user 
WHERE 
name LIKE '%'||#{name}||'%'

  

> SQL Server

SELECT 
* 
FROM 
user 
WHERE 
name LIKE '%'+#{name}+'%'

  

> MySQL

SELECT 
* 
FROM 
user 
WHERE 
name LIKE CONCAT('%',#{name},'%')

  

> DB2

SELECT 
* 
FROM 
user 
WHERE 
name LIKE CONCAT('%',#{name},'%')
或 
SELECT 
* 
FROM 
user 
WHERE 
name LIKE '%'||#{name}||'%' 

  

> 通用

SELECT 
* 
FROM 
user 
WHERE 1 = 1
<if test="name != null and name != ''">
<bind name="pattern" value="'%' + _parameter.name + '%'" />
AND name LIKE #{pattern}
</if>

  

    原文作者:MyBatis
    原文地址: https://www.cnblogs.com/icewee/articles/6927841.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞