Categories: MySQL FunctionsPHP

MySQL8 QUOTE() Functions – String Functions

QUOTE() function returns the string surrounded by single quotations and escapes the backslash in it.

The MySQL QUOTE() function quotes a string to produce a result that can be used as a properly escaped data value in an SQL statement. The string is returned enclosed by single quotation marks and with each instance of backslash (\), single quote (‘), ASCII NUL, and Control+Z preceded by a backslash.

Returns value is the word NULL without enclosing single quotation marks if the input is NULL. See example 2. It is useful in saving the values in the database.


MySQL QUOTE() Functions: Syntax

QUOTE ( string );

MySQL QUOTE() Functions: Parameter

[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|left|left|left”]
Name, Required /Optional,Type, Description
string, Required, String , It represents the valid input  (already) escaped string..
[/table]


MySQL QUOTE() Functions: Output

[table caption=”” width=”100%” colwidth=”100%” colalign=”left”]
Return
string surrounded by single quotations and escapes the backslash in it.
Returns value is the word NULL without enclosing single quotation marks if the input is NULL.[/table]


MySQL QUOTE() Functions: Available from

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, MySQL 5.7
[/table]


QUOTE() Example 1 : Very easy example

it makes MySQL‘s handling of the full string easier by covering the string with single quotes, and by preceding every single quote, backslash, ASCII NUL, and control-Z with a backslash. See the below example:

mysql> SELECT QUOTE('Shouldn\'t!');
+----------------------+
| QUOTE('Shouldn\'t!') |
+----------------------+
| 'Shouldn\'t!'        |
+----------------------+
1 row in set (0.05 sec)

The above example has returned the same string as input. while below example add \(backslash) to single quotation mark(‘).

mysql> SELECT QUOTE('Shouldn''t!');
+----------------------+
| QUOTE('Shouldn''t!') |
+----------------------+
| 'Shouldn\'t!'        |
+----------------------+
1 row in set (0.00 sec)

QUOTE() Example  2 : NULL arguments

See below example

mysql> SELECT QUOTE(NULL);
+-------------+
| QUOTE(NULL) |
+-------------+
| NULL        |
+-------------+
1 row in set (0.00 sec)

QUOTE() Example 3 :  Database Example

The QUOTE operator is often used to enclosed with a single quote for all employee’s names. See below example

mysql> select name, QUOTE(name) from tbl_employee;
+------------+--------------+
| name       | QUOTE(name)  |
+------------+--------------+
| Jyoti Rani | 'Jyoti Rani' |
| Polla      | 'Polla'      |
| Arnav      | 'Arnav'      |
| Jeevesh    | 'Jeevesh'    |
| Tom        | 'Tom'        |
+------------+--------------+
5 rows in set (0.03 sec)


See all MySQL String functions MySQL 8 String Functions.


Related articles : LOCATE(), HEX(), CONCAT(), CONCAT_WS() , LOWER(), LTRIM(), INSTR(), POSITION().


PHP Related articles : ADDSLASHES(), ADDCSLASHES(), QUOTEMETA(), STRIPSLASHES(), STRIPCSLASHES(), PHP STRING FUNCTIONS().

jyoti rani

Recent Posts

What Is a Progressive Web App? Why Would You Need One?

App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…

1 year ago

7 Most Popular Paid Online Advertising Strategy

As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…

1 year ago

The Importance of User-Centered Design in Mobile App Development

Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…

1 year ago

Healthcare Mobile App Development: A Complete Guide for Founders

COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…

1 year ago

Exploring Diverse WordPress Theme Niches: A Comprehensive Guide

Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…

1 year ago

8 Awesome Blog Content Ideas for Movers to Skyrocket the SEO

For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…

1 year ago