1. If you need to find the records with "three" and "cat" in U ﹣ name, please use and condition
Select * from [user] where u name like '% 3%' and u name like '% cat%'
If you use select * from [user] where u name like '% 3% cat%
Although we can search for "tripods", we can't search for "Zhang maosan" who meets the conditions.
2. Select * from [user] where u "name like" three "
Only find out that "Tang Sanzang" is three words and the middle one is "three";
3. Select * from [user] where u [name like '[Zhang liwang] 3'
"Zhang San", "Li San" and "Wang San" (instead of "Zhang Li Wang San") will be identified;
4.SELECT * FROM [user] WHERE u name LIKE 'three'
We will find out "Zhao San" and "Sun San" who are not surnamed "Zhang", "Li" and "Wang";
<select id="findList" resultType="Article"> SELECT <include refid="cmsArticleColumns"/> FROM cms_article a <include refid="cmsArticleJoins"/> <where> a.del_flag = #{delFlag} <if test="title != null and title != ''"> AND a.title LIKE <if test="dbName == 'oracle'">'%'||#{title}||'%'</if> <if test="dbName == 'mssql'">'%'+#{title}+'%'</if> **<if test="dbName == 'mysql'">**CONCAT**('%', #{title}, '%')</if>** </if> <if test="posid != null and posid != ''"> AND a.posid LIKE <if test="dbName == 'oracle'">'%'||#{posid}||'%'</if> <if test="dbName == 'mssql'">'%'+#{posid}+'%'</if> <if test="dbName == 'mysql'">CONCAT('%', #{posid}, '%')</if> </if> <if test="category.id != null and category.id != ''"> AND (a.category_id = #{category.id} <if test="category.parentIds != null and category.parentIds != ''"> or c.parent_ids like <if test="dbName == 'oracle'">'%'||#{category.id}||'%'</if> <if test="dbName == 'mssql'">'%,'+#{category.id}+',%'</if> <if test="dbName == 'mysql'">CONCAT('%,', #{category.id}, ',%')</if> </if>) </if> <if test="image != null and image != ''"> AND a.image = #{image} </if> <if test="createBy != null and createBy.id != null and createBy.id != ''"> AND a.create_by = #{createBy.id} </if> <!-- ${sqlMap.dsf}--> </where> <choose> <when test="page !=null and page.orderBy != null and page.orderBy != ''"> ORDER BY ${page.orderBy} </when> <otherwise> ORDER BY a.weight DESC, a.update_date DESC </otherwise> </choose> </select>
SQL - concat (string join function)
MySQL: CONCAT()
Oracle: CONCAT(), ||
SQL Server: +
The syntax of CONCAT() is as follows:
Concat (string 1, string 2, string 3 ): String 1, string 2, string 3, etc. together.
Note that Oracle's CONCAT() only allows two parameters
In other words, you can only string two words at a time. However, in Oracle, we can use '|' to concatenate multiple strings at once.
Let's look at a few examples. Suppose we have the following table:
Geography table
region_name store_name
East Boston
East New York
West Los Angeles
West San Diego
Example 1:
MySQL/Oracle:
SELECT CONCAT(region_name,store_name) FROM Geography WHERE store_name = 'Boston';
Results:
'EastBoston'
Example 2:
Oracle:
SELECT region_name || ' ' || store_name FROM Geography WHERE store_name = 'Boston';
Results:
'East Boston'
Example 3:
SQL Server:
SELECT region_name + ' ' + store_name FROM Geography WHERE store_name = 'Boston';
Results:
'East Boston'