为什么 MySQL 在 INSERT INTO 中拒绝在字符串中插入竖线 ('|') 字符?
mysqlmysqli database
要在 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)