Our Recommendation for You Search your Query, You can find easily. for example search by book name or course name or any other which is related to your education

label name

PHP

MySQL Functions

MySQL Functions


MySQL has many built-in functions.
This reference contains the string, numeric, date, and advanced functions in MySQL.

MySQL String Functions

FunctionDescription
ASCIIReturns the number code that represents the specific character
CHAR_LENGTHReturns the length of the specified string (in characters)
CHARACTER_LENGTHReturns the length of the specified string (in characters)
CONCATConcatenates two or more expressions together
CONCAT_WSConcatenates two or more expressions together and adds a separator between them
FIELDReturns the position of a value in a list of values
FIND_IN_SETReturns the position of a string in a string list
FORMATFormats a number as a format of "#,###.##", rounding it to a certain number of decimal places
INSERTInserts a substring into a string at a specified position for a certain number of characters
INSTRReturns the position of the first occurrence of a string in another string
LCASEConverts a string to lower-case
LEFTExtracts a substring from a string (starting from left)
LENGTHReturns the length of the specified string (in bytes)
LOCATEReturns the position of the first occurrence of a substring in a string
LOWERConverts a string to lower-case
LPADReturns a string that is left-padded with a specified string to a certain length
LTRIMRemoves leading spaces from a string
MIDExtracts a substring from a string (starting at any position)
POSITIONReturns the position of the first occurrence of a substring in a string
REPEATRepeats a string a specified number of times
REPLACEReplaces all occurrences of a specified string
REVERSEReverses a string and returns the result
RIGHTExtracts a substring from a string (starting from right)
RPADReturns a string that is right-padded with a specified string to a certain length
RTRIMRemoves trailing spaces from a string
SPACEReturns a string with a specified number of spaces
STRCMPTests whether two strings are the same
SUBSTRExtracts a substring from a string (starting at any position)
SUBSTRINGExtracts a substring from a string (starting at any position)
SUBSTRING_INDEXReturns the substring of string before number of occurrences of delimiter
TRIMRemoves leading and trailing spaces from a string
UCASEConverts a string to upper-case
UPPERConverts a string to upper-case

MySQL Numeric Functions

FunctionDescription
ABSReturns the absolute value of a number
ACOSReturns the arc cosine of a number
ASINReturns the arc sine of a number
ATANReturns the arc tangent of a number or the arc tangent of n and m
ATAN2Returns the arc tangent of n and m
AVGReturns the average value of an expression
CEILReturns the smallest integer value that is greater than or equal to a number
CEILINGReturns the smallest integer value that is greater than or equal to a number
COSReturns the cosine of a number
COTReturns the cotangent of a number
COUNTReturns the number of records in a select query
DEGREESConverts a radian value into degrees
DIVUsed for integer division
EXPReturns e raised to the power of number
FLOORReturns the largest integer value that is less than or equal to a number
GREATESTReturns the greatest value in a list of expressions
LEASTReturns the smallest value in a list of expressions
LNReturns the natural logarithm of a number
LOGReturns the natural logarithm of a number or the logarithm of a number to a specified base
LOG10Returns the base-10 logarithm of a number
LOG2Returns the base-2 logarithm of a number
MAXReturns the maximum value of an expression
MINReturns the minimum value of an expression
MODReturns the remainder of n divided by m
PIReturns the value of PI displayed with 6 decimal places
POWReturns m raised to the nth power
POWERReturns m raised to the nth power
RADIANSConverts a value in degrees to radians
RANDReturns a random number or a random number within a range
ROUNDReturns a number rounded to a certain number of decimal places
SIGNReturns a value indicating the sign of a number
SINReturns the sine of a number
SQRTReturns the square root of a number
SUMReturns the summed value of an expression
TANReturns the tangent of a number
TRUNCATEReturns a number truncated to a certain number of decimal places

MySQL Date Functions

FunctionDescription
ADDDATEReturns a date after a certain time/date interval has been added
ADDTIMEReturns a time/datetime after a certain time interval has been added
CURDATEReturns the current date
CURRENT_DATEReturns the current date
CURRENT_TIMEReturns the current time
CURRENT_TIMESTAMPReturns the current date and time
CURTIMEReturns the current time
DATEExtracts the date value from a date or datetime expression
DATEDIFFReturns the difference in days between two date values
DATE_ADDReturns a date after a certain time/date interval has been added
DATE_FORMATFormats a date as specified by a format mask
DATE_SUBReturns a date after a certain time/date interval has been subtracted
DAYReturns the day portion of a date value
DAYNAMEReturns the weekday name for a date
DAYOFMONTHReturns the day portion of a date value
DAYOFWEEKReturns the weekday index for a date value
DAYOFYEARReturns the day of the year for a date value
EXTRACTExtracts parts from a date
FROM_DAYSReturns a date value from a numeric representation of the day
HOURReturns the hour portion of a date value
LAST_DAYReturns the last day of the month for a given date
LOCALTIMEReturns the current date and time
LOCALTIMESTAMPReturns the current date and time
MAKEDATEReturns the date for a certain year and day-of-year value
MAKETIMEReturns the time for a certain hour, minute, second combination
MICROSECONDReturns the microsecond portion of a date value
MINUTEReturns the minute portion of a date value
MONTHReturns the month portion of a date value
MONTHNAMEReturns the full month name for a date
NOWReturns the current date and time
PERIOD_ADDTakes a period and adds a specified number of months to it
PERIOD_DIFFReturns the difference in months between two periods
QUARTERReturns the quarter portion of a date value
SECONDReturns the second portion of a date value
SEC_TO_TIMEConverts numeric seconds into a time value
STR_TO_DATETakes a string and returns a date specified by a format mask
SUBDATEReturns a date after which a certain time/date interval has been subtracted
SUBTIMEReturns a time/datetime value after a certain time interval has been subtracted
SYSDATEReturns the current date and time
TIMEExtracts the time value from a time/datetime expression
TIME_FORMATFormats a time as specified by a format mask
TIME_TO_SECConverts a time value into numeric seconds
TIMEDIFFReturns the difference between two time/datetime values
TIMESTAMPConverts an expression to a datetime value and if specified adds an optional time interval to the value
TO_DAYSConverts a date into numeric days
WEEKReturns the week portion of a date value
WEEKDAYReturns the weekday index for a date value
WEEKOFYEARReturns the week of the year for a date value
YEARReturns the year portion of a date value
YEARWEEKReturns the year and week for a date value

MySQL Advanced Functions

FunctionDescription
BINConverts a decimal number to a binary number
BINARYConverts a value to a binary string
CASELets you evaluate conditions and return a value when the first condition is met
CASTConverts a value from one datatype to another datatype
COALESCEReturns the first non-null expression in a list
CONNECTION_IDReturns the unique connection ID for the current connection
CONVConverts a number from one number base to another
CONVERTConverts a value from one datatype to another, or one character set to another
CURRENT_USERReturns the user name and host name for the MySQL account used by the server to authenticate the current client
DATABASEReturns the name of the default database
IFReturns one value if a condition is TRUE, or another value if a condition is FALSE
IFNULLLets you to return an alternate value if an expression is NULL
ISNULLTests whether an expression is NULL
LAST_INSERT_IDReturns the first AUTO_INCREMENT value that was set by the most recent INSERT or UPDATE statement
NULLIFCompares two expressions
SESSION_USERReturns the user name and host name for the current MySQL user
SYSTEM_USERReturns the user name and host name for the current MySQL user
USERReturns the user name and host name for the current MySQL user
VERSIONReturns the version of the MySQL database