我们可以在MySQL查询中使用“ LIKE concat()”吗?

Can we use “LIKE concat()” in a MySQL query?

是的,我们可以做到。 让我们首先创建一个表-

1
2
3
4
5
mysql> create table DemoTable
(
 Name varchar(50)
);
Query OK, 0 rows affected (0.63 sec)

使用insert命令在表中插入一些记录-

1
2
3
4
5
6
7
8
mysql> insert into DemoTable values('John');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('Adam');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values('Bob');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable values('Mike');
Query OK, 1 row affected (0.16 sec)

使用select语句显示表中的所有记录-

1
mysql> select *from DemoTable;

这将产生以下输出-

1
2
3
4
5
6
7
8
9
+------+
| Name |
+------+
| John |
| Adam |
| Bob  |
| Mike |
+------+
4 rows in set (0.00 sec)

以下是在MySQL中使用" LIKE concat()"的查询-

1
mysql> select Name from DemoTable where Name LIKE concat('%','o','%');

这将产生以下输出-

1
2
3
4
5
6
7
+------+
| Name |
+------+
| John |
| Bob  |
+------+
2 rows in set (0.03 sec)