MySQL QUOTE() 函數可用來附加帶有單引號的列值。為此,我們必須將列名作為 QUOTE() 函數的參數傳遞。下面用「Student」表的資料來示範
mysql> Select Name, ID, QUOTE(Subject)AS Subject from Student; +---------+------+-------------+ | Name | ID | Subject | +---------+------+-------------+ | Gaurav | 1 | 'Computers' | | Aarav | 2 | 'History' | | Harshit | 15 | 'Commerce' | | Gaurav | 20 | 'Computers' | | Yashraj | 21 | 'Math' | +---------+------+-------------+ 5 rows in set (0.00 sec)
相反,也可以藉助 CONCAT() 函數來完成,如下所示 -
mysql> Select Name, ID, CONCAT('''',Subject,'''')AS Subject from Student; +---------+------+-------------+ | Name | ID | Subject | +---------+------+-------------+ | Gaurav | 1 | 'Computers' | | Aarav | 2 | 'History' | | Harshit | 15 | 'Commerce' | | Gaurav | 20 | 'Computers' | | Yashraj | 21 | 'Math' | +---------+------+-------------+ 5 rows in set (0.00 sec)
為此目的,QUOTE() 函數非常容易使用。
以上是哪個 MySQL 函數可用來附加帶有單引號的列值?的詳細內容。更多資訊請關注PHP中文網其他相關文章!