如何在MySQL列的字符串的左侧和中间部分转义'%'字符?
让我们首先创建一个表-
mysql> create table DemoTable629 (StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,StudentSubject text);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable629(StudentSubject) values('MySQL%'); mysql> insert into DemoTable629(StudentSubject) values('Spring%Hibernate'); mysql> insert into DemoTable629(StudentSubject) values('%Java');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable629;
这将产生以下输出-
+-----------+------------------+ | StudentId | StudentSubject | +-----------+------------------+ | 1 | MySQL% | | 2 | Spring%Hibernate | | 3 | %Java | +-----------+------------------+ 3 rows in set (0.00 sec)
以下是转义'%'字符的查询-
mysql> select *from DemoTable629 where StudentSubject like '%\%';
这将产生以下输出-
+-----------+----------------+ | StudentId | StudentSubject | +-----------+----------------+ | 1 | MySQL% | +-----------+----------------+ 1 row in set (0.00 sec)