欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

主流数据库在mybatis中LIKE模糊查询的几种写法

程序员文章站 2022-06-07 16:02:27
...

主流数据库在mybatis中LIKE模糊查询的几种写法

1. oracle

<select id="searchUserBySearchName" parameterType="java.lang.String" resultType="com.urm.entity.User">
	select * from t_user where user_name like CONCAT('%',#{search_name},'%')
</select>

或者

<select id="searchUserBySearchName" parameterType="java.lang.String" resultType="com.urm.entity.User">
	select * from t_user where user_name like '%'||#{search_name}||'%' 
</select>

2. mysql

<select id="searchUserBySearchName" parameterType="java.lang.String" resultType="com.urm.entity.User">
	select * from t_user where user_name like CONCAT('%',#{search_name},'%')
</select>

3. sql server

<select id="searchUserBySearchName" parameterType="java.lang.String" resultType="com.urm.entity.User">
	select * from t_user where user_name like '%'+#{search_name}+'%'
</select>

4. db2 (与oracle相同)

<select id="searchUserBySearchName" parameterType="java.lang.String" resultType="com.urm.entity.User">
	select * from t_user where user_name like CONCAT('%',#{search_name},'%')  
</select>

或者

<select id="searchUserBySearchName" parameterType="java.lang.String" resultType="com.urm.entity.User">
	select * from t_user where user_name like '%'||#{search_name}||'%' 
</select>