MySQL 的函式和操作符
阿新 • • 發佈:2022-01-05
https://dev.mysql.com/doc/refman/8.0/en/functions.html
https://dev.mysql.com/doc/refman/8.0/en/non-typed-operators.html
https://dev.mysql.com/doc/refman/8.0/en/flow-control-functions.html
https://dev.mysql.com/doc/refman/8.0/en/numeric-functions.html
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html
https://dev.mysql.com/doc/refman/8.0/en/string-functions.html
https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html
1、操作符
Name | Description | Introduced | Deprecated |
---|---|---|---|
& | Bitwise AND | ||
> | Greater than operator | ||
>> | Right shift | ||
>= | Greater than or equal operator | ||
< | Less than operator | ||
<>, != | Not equal operator | ||
<< | Left shift | ||
<= | Less than or equal operator | ||
<=> | NULL-safe equal to operator | ||
%, MOD | Modulo operator | ||
* | Multiplication operator | ||
+ | Addition operator | ||
- | Minus operator | ||
- | Change the sign of the argument | ||
-> | Return value from JSON column after evaluating path; equivalent to JSON_EXTRACT(). | ||
->> | Return value from JSON column after evaluating path and unquoting the result; equivalent to JSON_UNQUOTE(JSON_EXTRACT()). | ||
/ | Division operator | ||
:= | Assign a value | ||
= | Assign a value (as part of a SET statement, or as part of the SET clause in an UPDATE statement) | ||
= | Equal operator | ||
^ | Bitwise XOR | ||
AND, && | Logical AND | ||
BETWEEN ... AND ... | Whether a value is within a range of values | ||
BINARY | Cast a string to a binary string | 8.0.27 | |
CASE | Case operator | ||
DIV | Integer division | ||
IN() | Whether a value is within a set of values | ||
IS | Test a value against a boolean | ||
IS NOT | Test a value against a boolean | ||
IS NOT NULL | NOT NULL value test | ||
IS NULL | NULL value test | ||
LIKE | Simple pattern matching | ||
MEMBER OF() | Returns true (1) if first operand matches any element of JSON array passed as second operand, otherwise returns false (0) | 8.0.17 | |
NOT, ! | Negates value | ||
NOT BETWEEN ... AND ... | Whether a value is not within a range of values | ||
NOT IN() | Whether a value is not within a set of values | ||
NOT LIKE | Negation of simple pattern matching | ||
NOT REGEXP | Negation of REGEXP | ||
OR, | Logical OR | ||
REGEXP | Whether string matches regular expression | ||
RLIKE | Whether string matches regular expression | ||
SOUNDS LIKE | Compare sounds | ||
XOR | Logical XOR | ||
Bitwise OR | |||
~ | Bitwise inversion |
2、流程控制函式
Name | Description |
---|---|
CASE | Case operator |
IF() | If/else construct |
IFNULL() | Null if/else construct |
NULLIF() | Return NULL if expr1 = expr2 |
3、算數相關的操作符和函式
Name | Description |
---|---|
%, MOD | Modulo operator |
* | Multiplication operator |
+ | Addition operator |
- | Minus operator |
- | Change the sign of the argument |
/ | Division operator |
ABS() | Return the absolute value |
ACOS() | Return the arc cosine |
ASIN() | Return the arc sine |
ATAN() | Return the arc tangent |
ATAN2(), ATAN() | Return the arc tangent of the two arguments |
CEIL() | Return the smallest integer value not less than the argument |
CEILING() | Return the smallest integer value not less than the argument |
CONV() | Convert numbers between different number bases |
COS() | Return the cosine |
COT() | Return the cotangent |
CRC32() | Compute a cyclic redundancy check value |
DEGREES() | Convert radians to degrees |
DIV | Integer division |
EXP() | Raise to the power of |
FLOOR() | Return the largest integer value not greater than the argument |
LN() | Return the natural logarithm of the argument |
LOG() | Return the natural logarithm of the first argument |
LOG10() | Return the base-10 logarithm of the argument |
LOG2() | Return the base-2 logarithm of the argument |
MOD() | Return the remainder |
PI() | Return the value of pi |
POW() | Return the argument raised to the specified power |
POWER() | Return the argument raised to the specified power |
RADIANS() | Return argument converted to radians |
RAND() | Return a random floating-point value |
ROUND() | Round the argument |
SIGN() | Return the sign of the argument |
SIN() | Return the sine of the argument |
SQRT() | Return the square root of the argument |
TAN() | Return the tangent of the argument |
TRUNCATE() | Truncate to specified number of decimal places |
4、日期相關的函式
Name | Description |
---|---|
ADDDATE() | Add time values (intervals) to a date value |
ADDTIME() | Add time |
CONVERT_TZ() | Convert from one time zone to another |
CURDATE() | Return the current date |
CURRENT_DATE(), CURRENT_DATE | Synonyms for CURDATE() |
CURRENT_TIME(), CURRENT_TIME | Synonyms for CURTIME() |
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP | Synonyms for NOW() |
CURTIME() | Return the current time |
DATE() | Extract the date part of a date or datetime expression |
DATE_ADD() | Add time values (intervals) to a date value |
DATE_FORMAT() | Format date as specified |
DATE_SUB() | Subtract a time value (interval) from a date |
DATEDIFF() | Subtract two dates |
DAY() | Synonym for DAYOFMONTH() |
DAYNAME() | Return the name of the weekday |
DAYOFMONTH() | Return the day of the month (0-31) |
DAYOFWEEK() | Return the weekday index of the argument |
DAYOFYEAR() | Return the day of the year (1-366) |
EXTRACT() | Extract part of a date |
FROM_DAYS() | Convert a day number to a date |
FROM_UNIXTIME() | Format Unix timestamp as a date |
GET_FORMAT() | Return a date format string |
HOUR() | Extract the hour |
LAST_DAY | Return the last day of the month for the argument |
LOCALTIME(), LOCALTIME | Synonym for NOW() |
LOCALTIMESTAMP, LOCALTIMESTAMP() | Synonym for NOW() |
MAKEDATE() | Create a date from the year and day of year |
MAKETIME() | Create time from hour, minute, second |
MICROSECOND() | Return the microseconds from argument |
MINUTE() | Return the minute from the argument |
MONTH() | Return the month from the date passed |
MONTHNAME() | Return the name of the month |
NOW() | Return the current date and time |
PERIOD_ADD() | Add a period to a year-month |
PERIOD_DIFF() | Return the number of months between periods |
QUARTER() | Return the quarter from a date argument |
SEC_TO_TIME() | Converts seconds to 'hh:mm:ss' format |
SECOND() | Return the second (0-59) |
STR_TO_DATE() | Convert a string to a date |
SUBDATE() | Synonym for DATE_SUB() when invoked with three arguments |
SUBTIME() | Subtract times |
SYSDATE() | Return the time at which the function executes |
TIME() | Extract the time portion of the expression passed |
TIME_FORMAT() | Format as time |
TIME_TO_SEC() | Return the argument converted to seconds |
TIMEDIFF() | Subtract time |
TIMESTAMP() | With a single argument, this function returns the date or datetime expression; with two arguments, the sum of the arguments |
TIMESTAMPADD() | Add an interval to a datetime expression |
TIMESTAMPDIFF() | Subtract an interval from a datetime expression |
TO_DAYS() | Return the date argument converted to days |
TO_SECONDS() | Return the date or datetime argument converted to seconds since Year 0 |
UNIX_TIMESTAMP() | Return a Unix timestamp |
UTC_DATE() | Return the current UTC date |
UTC_TIME() | Return the current UTC time |
UTC_TIMESTAMP() | Return the current UTC date and time |
WEEK() | Return the week number |
WEEKDAY() | Return the weekday index |
WEEKOFYEAR() | Return the calendar week of the date (1-53) |
YEAR() | Return the year |
YEARWEEK() | Return the year and week |
5、字串
Name | Description |
---|---|
ASCII() | Return numeric value of left-most character |
BIN() | Return a string containing binary representation of a number |
BIT_LENGTH() | Return length of argument in bits |
CHAR() | Return the character for each integer passed |
CHAR_LENGTH() | Return number of characters in argument |
CHARACTER_LENGTH() | Synonym for CHAR_LENGTH() |
CONCAT() | Return concatenated string |
CONCAT_WS() | Return concatenate with separator |
ELT() | Return string at index number |
EXPORT_SET() | Return a string such that for every bit set in the value bits, you get an on string and for every unset bit, you get an off string |
FIELD() | Index (position) of first argument in subsequent arguments |
FIND_IN_SET() | Index (position) of first argument within second argument |
FORMAT() | Return a number formatted to specified number of decimal places |
FROM_BASE64() | Decode base64 encoded string and return result |
HEX() | Hexadecimal representation of decimal or string value |
INSERT() | Insert substring at specified position up to specified number of characters |
INSTR() | Return the index of the first occurrence of substring |
LCASE() | Synonym for LOWER() |
LEFT() | Return the leftmost number of characters as specified |
LENGTH() | Return the length of a string in bytes |
LIKE | Simple pattern matching |
LOAD_FILE() | Load the named file |
LOCATE() | Return the position of the first occurrence of substring |
LOWER() | Return the argument in lowercase |
LPAD() | Return the string argument, left-padded with the specified string |
LTRIM() | Remove leading spaces |
MAKE_SET() | Return a set of comma-separated strings that have the corresponding bit in bits set |
MATCH() | Perform full-text search |
MID() | Return a substring starting from the specified position |
NOT LIKE | Negation of simple pattern matching |
NOT REGEXP | Negation of REGEXP |
OCT() | Return a string containing octal representation of a number |
OCTET_LENGTH() | Synonym for LENGTH() |
ORD() | Return character code for leftmost character of the argument |
POSITION() | Synonym for LOCATE() |
QUOTE() | Escape the argument for use in an SQL statement |
REGEXP | Whether string matches regular expression |
REGEXP_INSTR() | Starting index of substring matching regular expression |
REGEXP_LIKE() | Whether string matches regular expression |
REGEXP_REPLACE() | Replace substrings matching regular expression |
REGEXP_SUBSTR() | Return substring matching regular expression |
REPEAT() | Repeat a string the specified number of times |
REPLACE() | Replace occurrences of a specified string |
REVERSE() | Reverse the characters in a string |
RIGHT() | Return the specified rightmost number of characters |
RLIKE | Whether string matches regular expression |
RPAD() | Append string the specified number of times |
RTRIM() | Remove trailing spaces |
SOUNDEX() | Return a soundex string |
SOUNDS LIKE | Compare sounds |
SPACE() | Return a string of the specified number of spaces |
STRCMP() | Compare two strings |
SUBSTR() | Return the substring as specified |
SUBSTRING() | Return the substring as specified |
SUBSTRING_INDEX() | Return a substring from a string before the specified number of occurrences of the delimiter |
TO_BASE64() | Return the argument converted to a base-64 string |
TRIM() | Remove leading and trailing spaces |
UCASE() | Synonym for UPPER() |
UNHEX() | Return a string containing hex representation of a number |
UPPER() | Convert to uppercase |
WEIGHT_STRING() | Return the weight string for a string |
6、型別轉換
Name | Description | Deprecated |
---|---|---|
BINARY | Cast a string to a binary string | 8.0.27 |
CAST() | Cast a value as a certain type | |
CONVERT() | Cast a value as a certain type |