Why does MySQL refuse pipe ('|') character in string on INSERT INTO?


To insert pipe(|) character in string on INSERT INTO, let us first see an example and create a table. The query to create a table is as follows

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

Insert some records in the table using insert command. The query is as follows −

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)

Display all records from the table using select statement. The query is as follows −

mysql> select *from PipeInsertDemo;

The following is the output

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

Updated on: 30-Jul-2019

203 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements