1. 程式人生 > >MySQL:雙引號和單引號

MySQL:雙引號和單引號

在標準 SQL 中,字串使用的是單引號

如果字串本身也包括單引號,則使用兩個單引號(注意,不是雙引號,字串中的雙引號不需要另外轉義)。

如:

insert into tableA (id, name) values (1, 'abc');
insert into tableA (id, name) values (2, '"abc');
insert into tableA (id, name) values (3, 'a''bc');
select * from tablea;

輸出:

+----+------+
| id | name |
+----+------+
| 1 | abc | | 2 | "abc | | 3 | a'bc | +----+------+ 3 rows in set

mysql中也允許用雙引號表示字串,但是這不是標準是擴充套件,最好不用,oracal中只允許用單引號。