「MariaDB」QUOTE関数で値をシングルクォートで囲むサンプル

環境
Windows 10 64 bit
MariaDB 10.6.4

書式
QUOTE( 値 )
QUOTE関数を使用することで、数値や文字列などの値をシングルクオートで囲み特殊文字をエスケープします。
使用例
1.数値をシングルクォートで囲みます

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> SELECT QUOTE(345) result;
+--------+
| result |
+--------+
| '345' |
+--------+
1 row in set (0.028 sec)
MariaDB [(none)]> SELECT QUOTE(345) result; +--------+ | result | +--------+ | '345' | +--------+ 1 row in set (0.028 sec)
MariaDB [(none)]> SELECT QUOTE(345) result;
+--------+
| result |
+--------+
| '345'  |
+--------+
1 row in set (0.028 sec)

2.マイナス数値の場合

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> SELECT QUOTE( -6.5435 ) result;
+-----------+
|  result |
+-----------+
| '-6.5435' |
+-----------+
1 row in set (0.056 sec)
MariaDB [(none)]> SELECT QUOTE( -6.5435 ) result; +-----------+ |  result | +-----------+ | '-6.5435' | +-----------+ 1 row in set (0.056 sec)
MariaDB [(none)]> SELECT QUOTE( -6.5435 ) result;
+-----------+
|  result  |
+-----------+
| '-6.5435' |
+-----------+
1 row in set (0.056 sec)

3.文字列をシングルクォートで囲む

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> SELECT QUOTE( 'study' ) result;
+---------+
| result |
+---------+
| 'study' |
+---------+
1 row in set (0.000 sec)
MariaDB [(none)]> SELECT QUOTE( 'study' ) result; +---------+ | result | +---------+ | 'study' | +---------+ 1 row in set (0.000 sec)
MariaDB [(none)]> SELECT QUOTE( 'study' ) result;
+---------+
| result  |
+---------+
| 'study' |
+---------+
1 row in set (0.000 sec)

4.引数がNULLの場合

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> SELECT QUOTE( NULL ) result;
+----------+
|  result |
+----------+
| NULL |
+----------+
1 row in set (0.023 sec)
MariaDB [(none)]> SELECT QUOTE( NULL ) result; +----------+ |  result | +----------+ | NULL | +----------+ 1 row in set (0.023 sec)
MariaDB [(none)]> SELECT QUOTE( NULL ) result;
+----------+
|  result |
+----------+
| NULL     |
+----------+
1 row in set (0.023 sec)

 

MariaDB

Posted by arkgame