- 先看一下常规的插入:
insert into user VALUES (125,'王小'二'',98);
insert into user VALUES (124,'王'小'二',98);
- 这样会报错:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near '二'',98)' at line 1
-
引起原因:
mysql会自动把’‘进行配对,这样第一条sql就是字符串’王小’后面突然出现个字符串,这样就会报错,字符串要用’’. -
解决:添加转义字符
insert into user VALUES (125,'王小\'二\'',98);
insert into user VALUES (124,'王\'小\'二',98);
- 插入结果:
更多推荐