MyBatis中Like語句使用總結

hugh Lee發表於2017-07-29

Oracle資料庫:

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

或 :

SELECT  
*  
FROM  
user  
WHERE  
name like '%'||#{name}||'%'  

SQLServer資料庫:

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}||'%'  

使用mybatis標籤:

<select id="selectPersons" resultType="person" parameterType="person">  
  <bind name="pattern" value="'%' + _parameter.username + '%'" />  
  select id,sex,age,username,password   
  from person  
  where username LIKE #{pattern}  
</select>  

相關文章