# String Literals

Strings are sequences of characters and enclosed with quotes.

The syntax is:

```sql
[_charset_name]'string' [COLLATE collation_name]
```

For example:

```sql
'The MariaDB Foundation'
_utf8 'Foundation' COLLATE utf8_unicode_ci;
```

Strings can either be enclosed in single quotes or in double quotes (the same character must be used to both open and close the string).

The ANSI SQL-standard does not permit double quotes for enclosing strings, and although MariaDB does by default, if the MariaDB server has enabled the [ANSI\_QUOTES\_SQL](https://mariadb.com/docs/server/server-management/variables-and-modes/sql_mode#ansi_quotes) [SQL\_MODE](https://mariadb.com/docs/server/server-management/variables-and-modes/sql_mode), double quotes will be treated as being used for [identifiers](https://mariadb.com/docs/server/reference/sql-structure/sql-language-structure/identifier-names) instead of strings.

Strings that are next to each other are automatically concatenated. The following are equivalent:

```
'The ' 'MariaDB ' 'Foundation'
```

```
'The MariaDB Foundation'
```

The `\` (backslash character) is used to escape characters (unless the [SQL\_MODE](https://mariadb.com/docs/server/server-management/variables-and-modes/sql_mode) hasn't been set to [NO\_BACKSLASH\_ESCAPES](https://mariadb.com/docs/server/server-management/variables-and-modes/sql_mode#no_backslash_escapes)):

```
'MariaDB's new features'
```

That is not a valid string because of the single quote in the middle of the string, which is treated as if it closes the string, but is actually meant as part of the string, an apostrophe. The backslash character helps in situations like this:

```
'MariaDB\'s new features'
```

That is now a valid string, and if displayed, will appear without the backslash.

```sql
SELECT 'MariaDB\'s new features';
+------------------------+
| MariaDB's new features |
+------------------------+
| MariaDB's new features |
+------------------------+
```

Another way to escape the quoting character is repeating it twice:

```sql
SELECT 'I''m here', """Double""";
+----------+----------+
| I'm here | "Double" |
+----------+----------+
| I'm here | "Double" |
+----------+----------+
```

## Escape Sequences

There are other escape sequences:

| Escape sequence | Character                                           |
| --------------- | --------------------------------------------------- |
| \0              | ASCII NUL (0x00).                                   |
| '               | Single quote (“'”).                                 |
| "               | Double quote (“"”).                                 |
| \b              | Backspace.                                          |
|                 | Newline, or linefeed,.                              |
|                 | Carriage return.                                    |
|                 | Tab.                                                |
| \Z              | ASCII 26 (Control+Z). See note following the table. |
| \\              | Backslash (“\”).                                    |
| %               | “%” character. See note following the table.        |
| \_              | A “\_” character. See note following the table.     |

Escaping the `%` and `_` characters can be necessary when using the [LIKE](https://mariadb.com/docs/server/reference/sql-functions/string-functions/like) operator, which treats them as special characters.

The ASCII 26 character (`\Z`) needs to be escaped when included in a batch file which needs to be executed in Windows. The reason is that ASCII 26, in Windows, is the end of file (EOF).

Backslash (`\`), if not used as an escape character, must always be escaped. When followed by a character that is not in the above table, backslashes will simply be ignored.

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-structure/sql-language-structure/string-literals.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
