How QUOTE() Works in MariaDB

In MariaDB, QUOTE() is a built-in string function that allows you to escape a string so that it’s suitable for inclusion in an SQL statement.

The string is returned enclosed by single quotes, and a backslash is prepended to each instance of single quote ('), backslash (\), ASCII NUL, and Control-Z characters.

Syntax

The syntax goes like this:

QUOTE(str)

Where str is the string to escape.

Example

Here’s a basic example:

SELECT QUOTE("Can't do it");

Result:

+----------------------+
| QUOTE("Can't do it") |
+----------------------+
| 'Can\'t do it'       |
+----------------------+

Empty String

Here’s what happens when an empty string is passed:

SELECT QUOTE("");

Result:

+-----------+
| QUOTE("") |
+-----------+
| ''        |
+-----------+

Null Argument

Providing null results in null:

SELECT QUOTE(null);

Result:

+-------------+
| QUOTE(null) |
+-------------+
| NULL        |
+-------------+

Missing Argument

Calling QUOTE() with the wrong number of arguments, or without passing any arguments results in an error:

SELECT QUOTE();

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'QUOTE'