為什麼 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.