Home  >  Article  >  Database  >  Complete list of commonly used functions in MySQL

Complete list of commonly used functions in MySQL

Guanhui
Guanhuiforward
2020-05-07 10:54:112029browse

String function

##RPAD(str,n,pad)Fill n pads on the rightmost side of strLTRIM(str)Remove the spaces on the left side of the string strRTRIM(str)Remove the spaces on the right side of the string strREPEAT(str,x)Return str to repeat x The result of timesSTRCMP(s1,s2)Compare strings s1 and s2REPLACE(str,a ,b)Replace all occurrences of string a in string str with string bTRIM(str)Remove the end of the string line and spaces at the beginning of the lineSUBSTRING(str,x,y)Returns a string with a length of y characters starting from the x position of the string str
Function Function
CONCAT(s1,s2,....) String connection
INSERT(str,x,y,instr) Replace the string from the specified start tag to the end with the specified string
LOWER(str) Convert all characters of the string to lowercase
UPPER(str) Convert all strings to uppercase
LEFT(str,x) Return the leftmost x characters of string str
RIGHT(str,x) Return the rightmost x characters of string str
LPAD(str,n,pad) Fill n pads on the leftmost side of str

Mathematical function

FunctionFunctionABS(x)Returns the absolute value of xCEIL(x)Returns the absolute value greater than x Minimum integer valueFLOOR(x)Returns the maximum integer value less than xMOD(x,y) Returns the modulus of x/yRAND()Returns a random value between 0 and 1ROUND(x,y)Returns the rounded value of parameter x with y decimal placesTRUNCATE(x,y)Return the result of number x truncated to y decimal places

Date and time functions

FunctionFunction##CURDATE()CURTIME()NOW()UNIX_TIMESTAMP(date)##FROM_UNIXTIMEReturns the date value of UNIX timestampWEEK(date)Returns the date as the week of the year Return the year of dateReturn the hour value of timeReturn the minute value of timeReturn the month name of date##DATE_FORMAT( date,fmt)Returns the date value in string fmt formatDATE_ADD(date,interval expr type)Returns a date or time Value plus the time value of a time intervalDATEDIFF(expr,expr2)Returns the number of days between the start time expr and the end time expr2Process function
Return the current date
Return the current time
Return the current date and time
Returns the UNIX timestamp of date date
##YEAR(date)
HOUR(time)
MINUTE(time)
MONTHNAME(date)

Function

FunctionIF(value,t f)If value is true, return t; otherwise return fIFNULL(value1,value2) If value1 is not empty, return value1, otherwise return value2CASE WHEN [value1] THEN[result1]...ELSE[default]ENDIf value1 is true, return result1, otherwise return resultCASE[expr] WHEN [value1]THEN[result1]...ELSE[default]ENDIf expr is equal to value1, return result1, otherwise return defaultOther commonly used functions

#Function

FunctionReturns the current database name Recommended tutorial: ""
##DATEBASE()
VERSION() Return the current database version
USER() Return the current login username
INET_ATON(ip) Returns the numerical representation of the ip address
INET_NTOA(num) Returns the numerical representation of the ip address
PASSWORD(str) Returns the encrypted version of the string str
MD5() Returns characters The md5 value of string str
MySQL Tutorial

The above is the detailed content of Complete list of commonly used functions in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete