Mybatis对Oracle、SQL Server、MySQL、DB2的like模糊查询

Oracle

SELECT
	*
FROM
	user
WHERE
	name LIKE CONCAT(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>