为什么 MySQL 在 INSERT INTO 中拒绝字符串的管道('|')字符?


若要将管道(|)字符插入 INSERT INTO 中的字符串,我们首先看一个示例并创建一个表。创建表的查询如下

mysql> create table PipeInsertDemo
   -> (
   -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> UserPassword varchar(100)
   -> );
Query OK, 0 rows affected (0.52 sec)

使用 insert 命令在表中插入一些记录。查询如下 −

mysql> insert into PipeInsertDemo(UserPassword) values('John123|');
Query OK, 1 row affected (0.15 sec)
mysql> insert into PipeInsertDemo(UserPassword) values('|123456CarolTaylor');
Query OK, 1 row affected (0.13 sec)
mysql> insert into PipeInsertDemo(UserPassword) values('Adam|345Smith');
Query OK, 1 row affected (0.20 sec)

使用 select 语句显示表中的所有记录。查询如下 −

mysql> select *from PipeInsertDemo;

以下是输出

+--------+--------------------+
| UserId | UserPassword       |
+--------+--------------------+
|      1 | John123|           |
|      2 | |123456CarolTaylor |
|      4 | Adam|345Smith      |
+--------+--------------------+
3 rows in set (0.00 sec)

更新于: 30-7-2019

238 次浏览量

开启你的 职业生涯

通过完成课程来获得认证

开始
广告
© . All rights reserved.