CONCAT用法
CONCAT('hel', 'lo')
#result: hello
拼接模糊查询语句
<select id="selectStaff" resultType="com.base.staff.entity.Staff">
select department, branch, staff_number, staff_name, staff_gender, staff_home_location, staff_in_date, staff_phone_number from staff where del_flag = '0'
<if test="params.staffName != null and params.staffName.trim() != ''">
and staff_name like CONCAT(CONCAT('%',#{params.staffName}),'%')
</if>
<if test="params.staffNumber != null and params.staffNumber.trim() != ''">
and staff_number like CONCAT(CONCAT('%',#{params.staffNumber}),'%')
</if>
</select>
拼接后的语句
如果#{params.staffName} 的传值是 Kalinda,结果为 %Kalinda%
本文探讨了CONCAT函数在数据库中的使用方法,通过实例展示了如何利用CONCAT进行字符串拼接,实现模糊查询功能,特别关注于在MyBatis中构建动态SQL语句的过程。
383

被折叠的 条评论
为什么被折叠?



