天天看點

mysql concat函數進行模糊查詢

concat() 函數,是用來連接配接字元串。

精确查詢: select * from user where name=”zhangsan” 

模糊查詢; select * from user where name like “%zhang%”

在實際的使用中,條件是作為參數傳遞進來的。 是以我們使用 concat() 函數

mybatis: 

select * from user where name like concat(“%”, #{name},”%”) 

原生SQL:

case when ?1 is null then 1=1 else name like CONCAT('%',?1,'%') END 

concat(str1,str2,str3,str4,……….); 連接配接字元串函數,會生成一個字元串