mysql5.6 functions

# Mathematical functions
(1) ABS(x)
returns the absolute value of x
(2) PI()
returns pi, which displays 6 decimal places by default
(3) SQRT(x)
returns the quadratic root of a non-negative number x
(4) MOD(x,y)
returns the remainder after dividing x by y
(5) CEIL(x), CEILING(x)
returns the smallest integer not less than x
(6) FLOOR(x)
returns the largest integer not greater than x
(7) ROUND(x) and ROUND(x,y)
The former returns the integer closest to x, that is, rounds x to the nearest 5; the latter returns the number closest to x, and its value is reserved to y digits after the decimal point. If y is a negative value, Then it will be reserved until x to y bits to the left of the decimal point
(8) SIGN(x)
returns the sign of the parameter x, -1 means negative number, 0 means 0, 1 means positive number
(9) POW(x, y) and, POWER(x ,y)
returns the value of x raised to the power of y
(10) EXP(x)
returns the value of e raised to the power of x
(11) LOG(x)
returns the natural logarithm of x, the logarithm of x relative to base e
(12) LOG10(x)
returns the base 10 logarithm of
x (13) RADIANS(x)
returns the value of x converted from degrees to radians
(14) DEGREES(x)
returns the value of x converted from radians to degrees
(15 ) ) SIN(x), ASIN(x)
The former returns the sine of x, where x is the given radian value; the latter returns the arcsine of x, where x is the sine
(16) COS(x), ACOS(x)
The former returns the cosine of x, where x is the given The latter returns the arc cosine of x, where x is the cosine
(17) TAN(x), ATAN(x)
The former returns the tangent of x, where x is the given radian value; the latter returns the arc tangent of x Value, x is the tangent
(18) COT(x)
returns the cotangent of the given radian value x

# string function
(1) CHAR_LENGTH(str)
calculates the number of characters in the string
(2) CONCAT(s1,s2,... )
returns the string generated by the connection parameters, one or more contents to be concatenated, if any one is NULL, the return value is NULL
(3) CONCAT_WS(x,s1,s2,...)
returns the concatenated string of multiple strings Strings with an x ​​between each
(4) INSERT(s1,x,len,s2)
returns the string s1 whose substring starts at position x and is replaced by the string s2 for len characters
(5 ) LOWER(str) and LCASE(str), UPPER(str) and UCASE(str)
The first two convert all letters in str to lowercase, and the latter two convert all letters in the string to uppercase
(6) LEFT (s,n), RIGHT(s,n)
The former returns the n characters from the leftmost of the string s, the latter returns the n characters from the rightmost of the string s
(7) LPAD(s1,len,s2 ), RPAD(s1,len,s2)
The former returns s1, and the left side is filled with the string s2 to the length of len characters. If the length of s1 is greater than len, the return value is shortened to len characters; the former returns s1, and the right side is filled with the string s2 to the length of len characters. If s1 If the length is greater than len, the return value is shortened to len characters
(8) LTRIM(s), RTRIM(s)
The former returns the string s, and all spaces on the left are deleted; the latter returns the string s, and all spaces on the right are Delete
(9) TRIM(s)
returns the string s after deleting the spaces on both sides
(10) TRIM(s1 FROM s)
deletes all substrings s1 at both ends of the string s, if s1 is not specified, it is deleted by default Spaces
(11) REPEAT(s,n)
returns a string consisting of repeated strings s, the number of strings equal to n
(12) SPACE(n)
returns a string consisting of n spaces
(13) REPLACE (s,s1,s2)
returns a string that replaces all strings s1 in string s with string s2
(14) STRCMP(s1,s2)
If all strings in s1 and s2 are the same, return 0 ;According to the current sorting order, if the first parameter is less than the second, it will return -1, otherwise it will return 1
(15) SUBSTRING(s,n,len), MID(s,n,len) The
two functions have the same effect, from Returns a string starting from the nth character and having a length of len in the string s
(16) LOCATE(str1,str), POSITION(str1 IN str), INSTR(str,str1) The
three functions have the same function, returning subcharacters The starting position of the string str1 in the string str (from the first few characters)
(17) REVERSE(s)
reverses the string s
(18) ELT(N,str1,str2,str3,str4,...)
returns the Nth string
(19) group_contact(s)
This function returns the current group The set of column splicing below, applicable to the scenario: the left side displays the group name, and the right side wants to display all member information under the group.
For example:
SELECT
c.business_no, GROUP_CONCAT(c.event) AS event_group
FROM
remote_msg c
GROUP BY c.business_no
HAVING event_group LIKE '%a%'
AND event_group LIKE '%b%';

The result is as follows:

business_no   event_group

123      a,b,c


. Which one is used depends on whether the function is used in a string or numeric context (6) MONTH(date) and MONTHNAME(date) the former returns the month in the specified date, the latter returns the name of the month in the specified date (7) DAYNAME (d), DAYOFWEEK(d), WEEKDAY(d)













DAYNAME(d) returns the English name of the working day corresponding to d, such as Sunday, Monday, etc.; DAYOFWEEK(d) returns the index of the corresponding week, 1 means Sunday, 2 means Monday; WEEKDAY(d) means the work corresponding to d Day index, 0 means Monday, 1 means Tuesday
(8) WEEK(d), WEEKOFYEAD(d)
The former calculates the date d is the week of the year, and the latter calculates the week of the year
(9 ) DAYOFYEAR(d), DAYOFMONTH(d)
The former returns d is the day of the year, the latter returns d is the day of the month
(10) YEAR(date), QUARTER(date), MINUTE(time ), SECOND(time)
YEAR(date) returns the year corresponding to the specified date, the range is 1970~2069; QUARTER(date) returns date corresponding to the quarter of the year, the range is 1~4; MINUTE(time) returns the corresponding time The number of minutes, the range is 0~59; SECOND(time) returns the second value of the specified time
(11) EXTRACE(type FROM date)
extracts a part from the date, the type can be YEAR, YEAR_MONTH, DAY_HOUR, DAY_MICROSECOND, DAY_MINUTE, DAY_SECOND
(12 ) TIME_TO_SEC(time)
returns the time parameter converted to seconds, the conversion formula is "3600*hours + 60*minutes + seconds"
(13) SEC_TO_TIME()
and TIME_TO_SEC(time) are inverse functions of each other, converting the second value to time Format
(14) DATE_ADD(date,INTERVAL expr type), ADD_DATE(date,INTERVAL expr type)
returns the time after adding the starting time to the expr type, such as DATE_ADD('2010-12-31 23:59:59', INTERVAL 1 SECOND) means adding 1 second to the first time
(15) DATE_SUB(date, INTERVAL expr type), SUBDATE(date, INTERVAL expr type)
returns the time after subtracting the expr type from the starting time
(16) ADDTIME (date,expr), SUBTIME(date,expr)
The former performs the time addition operation of the date, and the latter performs the time subtraction operation of the date

# Conditional judgment function
(1) IF(expr, v1, v2)
If expr is TRUE, return v1 , otherwise return v2
(2) IFNULL(v1, v2)
If v1 is not NULL, return v1, otherwise return v2
(3) CASE expr WHEN v1 THEN r1 [WHEN v2 THEN v2] [ELSE rn] END
If expr is equal to a vn, return the result after the corresponding position THEN, if you don't want to wait with all the values, return the rn after ELSE

# System information function
(1) VERSION()
to view the MySQL version number
(2) CONNECTION_ID()
to view the current user's number of connections
(3) USER(), CURRENT_USER(), SYSTEM_USER(), SESSION_USER() to
view the combination of username and host currently authenticated by the MySQL server, generally the return values ​​of these functions are the same
(4) CHARSET(str)
view The character set used by the string str
(5) COLLATION()
to view the string arrangement

# Encryption function
(1) PASSWORD(str)
calculates and returns the encrypted string password from the original plaintext password str. Note that the encryption of this function is a single It is directional (irreversible), so it should not be used in personal applications and should only be used in the authentication system of the MySQL server
(2) MD5 (str)
calculates an MD5 128-bit checksum for the string, and changes the value Return as a binary string of 32 hexadecimal digits
(3) ENCODE(str, pswd_str)
uses pswd_str as the password to encrypt str
(4) DECODE(crypt_str, pswd_str)
uses pswd_str as the password to decrypt the encrypted string crypt_str, crypt_str is the string returned by the ENCODE function

# Other functions
(1) FORMAT(x,n)
formats the number x and rounds it to n digits after the decimal point, and the result is returned as a string
(2) CONV(N ,from_base,to_base)
Conversion between different base numbers, the return value is the string representation of the value N, which is converted from from_base base to to_base base
(3) INET_ATON(expr)
Given a dotted address representation of a network address as a string, returns an integer representing the numerical value of the address, the address can be 4 or 8 bits
(4) INET_NTOA(expr)
Given a numeric network address (4 or 8 bits), Returns the point address representation of the address as a string
(5) BENCHMARK(count, expr)
repeatedly executes the expression expr count times, which can be used to calculate the speed at which MySQL processes the expression, and the result value is usually 0 (0 just means very fast, not without speed). Another role is to use it to report the execution time of the statement inside the MySQL client
(6) CONVERT (str USING charset)
uses the character set charset to represent the string str

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324593156&siteId=291194637