MySQL QUOTE Function

MySQL QUOTE function is one of the String Functions, which returns a string enclosed by a single quotation mark. Or you can use this function to escape the data value, i.e., backslash, single quote, ASCII NULL. Let us see how to write String QUOTE function with an example and the basic syntax of it is as shown below:

QUOTE(String_Expression)

MySQL QUOTE Function Example

The function escapes the backslash and single quote in a given string and returns the string surrounded by single quotations. The following query shows multiple ways to use this QUOTE method. Also, read about the MySQL REPLACE function.

SELECT QUOTE('Don\'t Do it') a;

SELECT QUOTE('Tutorial''Gateway') b;

SELECT QUOTE('Tutorial \'Gateway') c;
+----------------+---------------------+----------------------+
| a              | b                   | c                    |
+----------------+---------------------+----------------------+
| 'Don\'t Do it' | 'Tutorial\'Gateway' | 'Tutorial \'Gateway' |
+----------------+---------------------+----------------------+

You can also use this QUOTE function on a column of Data. This MySQL example shows you how to use this method in the Email column.

TIP: Please refer to the MySQL CONCAT and MySQL CONCAT_WS methods from the list of available MySQL string functions.

SELECT FirstName,
LastName,
      DepartmentName,
      QUOTE(DepartmentName),
      Email,
      QUOTE(Email)
FROM `MySQL Tutorial`.employe;
QUOTE Function Example