字符串
单引号,双引号都可以表示字符
sql 'a string' "another string"
转义字符
Escape Sequence | Character Represented by Sequence |
---|---|
\0 | An ASCII NUL (X’00’) character |
’ | A single quote (’) character |
" | A double quote (") character |
\b | A backspace character |
\n | A newline (linefeed) character |
\r | A carriage return character |
\t | A tab character |
\Z | ASCII 26 (Control+Z); see note following the table |
\ | A backslash () character |
% | A % character; see note following the table |
_ | A _ character; see note following the table |
例子
SELECT 'hello', '"hello"', '""hello""', 'hel''lo', '\'hello';
语句中包含引号
SELECT "hello", "'hello'", "''hello''", "hel""lo", "\"hello";
语句中包含引号
SELECT 'This\nIs\nFour\nLines';
数字
时间
十六进制
SELECT X'4D7953514C', CHARSET(X'4D7953514C');
二进制
SELECT b'1000001', CHARSET(b'1000001');
布尔
SELECT TRUE, true, FALSE, false;
-> 1, 1, 0, 0
null
SELECT * FROM my_table WHERE phone = NULL;
参考:
https://dev.mysql.com/doc/refman/8.0/en/literals.html