Overview mysql provides many built-in functions. Common functions include: string functions, date functions, numeric functions. I generally recommend that you use backend languages (php, java, c #, etc) similar functions are used in the background language, which reduces mysql pressure and ensures logic. String function merges string concat (s1, s2 ,...,
Overview mysql provides many built-in functions. Common functions include: string functions, date functions, numeric functions. I generally recommend that you use backend languages (php, java, c #, etc) similar functions are used in the background language, which reduces mysql pressure and ensures logic. String function merges string concat (s1, s2 ,...,
Overview
Mysql provides many built-in functions, including:
- String Functions
- Date Functions
- Numeric Functions
I generally recommend that you use similar functions in the background language (php, java, c #, etc.) to reduce mysql pressure and ensure logic.
String Functions
| Function |
Function |
| Merge strings |
| Concat (s1, s2 ,..., Sn) |
Link s1, s2 ,..., S3 is a string |
| Concat_ws (sp, s1, s2 ,..., S3) |
Replace s1, s2 ..., Connect the sn to a string and separate it with the sep character |
| Repeat (str, x) |
Repeat the str string x times, which is a subset of the concat function. |
| Lpad (str, n, pad) |
Pad the leftmost str string with the string until the length is n characters. |
| Rpad (str, n, pad) |
Pads the rightmost side of str with the string pad until the length is n characters. |
| Filter string |
| Trim (str) |
Removes the spaces at the end of the str line and the line header. |
| Ltrim (str) |
Removes spaces from the str line header. |
| Rtrim (str) |
Removes spaces at the end of the str line. |
| Lower (str) |
Converts all characters in the str string to lowercase letters. |
| Upper (str) |
Converts all characters in the str string to uppercase. |
| Truncate string |
| Left (str, x) |
Returns the leftmost x characters of the str string. |
| Right (str, x) |
Returns the rightmost x characters of the str string. |
| Substr (str, x, y) |
Truncates a substring of y characters starting from position x in str. |
| Position (substr, str) |
Returns the position of the substring substr that appears for the first time in the str string. |
| Replace string |
| Replace (str, a, B) |
Replace string a with string B |
| Insert (str, x, y, instr) |
Replace string 'str' with string instr from position x and string 'y '. |
| String Length |
| Length (str) |
Obtains the number of bytes stored by string 'str '. |
| Char_length (str) |
Returns the number of characters in the str string. |
| Bit_length (str) |
Obtains the bit bits in string str storage. |
| Miscellaneous |
| Strcmp (s1, s2) |
Compares string s1 and string s2 |
| Quote (str) |
Escape single quotes in str with a backslash |
| Reverse (str) |
Reverse string str |
| Ascii (char) |
Get ASCII code |
# For example, length, char_length, bit_lengthselect catename, length (catename), char_length (catename), bit_length (catename) from yz_category;
Numeric Functions
| Function |
Function |
| Abs (x) |
Returns the absolute value of x. |
| Ceil (x) |
Returns the smallest integer value greater than x. |
| Floor (x) |
Returns the largest integer less than x. |
| Mod (x, y) |
Returns the modulo of x/y. |
| Rand () |
Returns 0 ~ Random value in 1 |
| Round (x, y) |
Returns the rounded y-bit small value of x. |
| Truncate (x, y) |
Returns the result of truncating x to y decimal places. |
Date and Time Functions
| Function |
Function |
| Curdate () |
Returns the current date. |
| Curtime () |
Returns the current time. |
| Now () |
Returns the current date and time. |
| Unix_timestamp (date) |
Returns the unix timestamp of date. |
| From_unixtime |
Returns the date value of the unix timestamp. |
| Week (date) |
Returns the week number of the year from date. |
| Year (date) |
Returns the year of date. |
| Hour (time) |
Returns the hour value of time. |
| Minute (time) |
Returns the minute value of time. |
| Monthname (date) |
Returns the month name of date. |
| Date_format (date, fmt) |
Returns the string fmt formatted date value. |
| Date_add (date, interval expr type) |
Returns a date or time value plus a time interval value. |
| Datediff (expr, expr2) |
Returns the number of days between the start time and end time. |
For details and examples, see Chapter P79-2nd common functions in MySQL database development, optimization, management, and maintenance (MySQL 5th.