MySQL Functions


MySQL has many built-in functions.

This reference contains string, numeric, date, and some advanced functions in MySQL.


MySQL String Functions

Function Description
Returns the ASCII value for the specific character
Returns the length of a string (in characters)
Returns the length of a string (in characters)
Adds two or more expressions together
Adds two or more expressions together with a separator
Returns the index position of a value in a list of values
Returns the position of a string within a list of strings
Formats a number to a format like "#,###,###.##", rounded to a specified number of decimal places
Inserts a string within a string at the specified position and for a certain number of characters
Returns the position of the first occurrence of a string in another string
Converts a string to lower-case
Extracts a number of characters from a string (starting from left)
Returns the length of a string (in bytes)
Returns the position of the first occurrence of a substring in a string
Converts a string to lower-case
Left-pads a string with another string, to a certain length
Removes leading spaces from a string
Extracts a substring from a string (starting at any position)
Returns the position of the first occurrence of a substring in a string
Repeats a string as many times as specified
Replaces all occurrences of a substring within a string, with a new substring
Reverses a string and returns the result
Extracts a number of characters from a string (starting from right)
Right-pads a string with another string, to a certain length
Removes trailing spaces from a string
Returns a string of the specified number of space characters
Compares two strings
Extracts a substring from a string (starting at any position)
Extracts a substring from a string (starting at any position)
Returns a substring of a string before a specified number of delimiter occurs
Removes leading and trailing spaces from a string
Converts a string to upper-case
Converts a string to upper-case


MySQL Numeric Functions

Function Description
Returns the absolute value of a number
Returns the arc cosine of a number
Returns the arc sine of a number
Returns the arc tangent of one or two numbers
Returns the arc tangent of two numbers
Returns the average value of an expression
Returns the smallest integer value that is >= to a number
Returns the smallest integer value that is >= to a number
Returns the cosine of a number
Returns the cotangent of a number
Returns the number of records returned by a select query
Converts a value in radians to degrees
Used for integer division
Returns e raised to the power of a specified number
Returns the largest integer value that is <= to a number
Returns the greatest value of the list of arguments
Returns the smallest value of the list of arguments
Returns the natural logarithm of a number
Returns the natural logarithm of a number, or the logarithm of a number to a specified base
Returns the natural logarithm of a number to base 10
Returns the natural logarithm of a number to base 2
Returns the maximum value in a set of values
Returns the minimum value in a set of values
Returns the remainder of a number divided by another number
Returns the value of PI
Returns the value of a number raised to the power of another number
Returns the value of a number raised to the power of another number
Converts a degree value into radians
Returns a random number
Rounds a number to a specified number of decimal places
Returns the sign of a number
Returns the sine of a number
Returns the square root of a number
Calculates the sum of a set of values
Returns the tangent of a number
Truncates a number to the specified number of decimal places

MySQL Date Functions

Function Description
Adds a time/date interval to a date and then returns the date
Adds a time interval to a time/datetime and then returns the time/datetime
Returns the current date
Returns the current date
Returns the current time
Returns the current date and time
Returns the current time
Extracts the date part from a datetime expression
Returns the number of days between two date values
Adds a time/date interval to a date and then returns the date
Formats a date
Subtracts a time/date interval from a date and then returns the date
Returns the day of the month for a given date
Returns the weekday name for a given date
Returns the day of the month for a given date
Returns the weekday index for a given date
Returns the day of the year for a given date
Extracts a part from a given date
Returns a date from a numeric datevalue
Returns the hour part for a given date
Extracts the last day of the month for a given date
Returns the current date and time
Returns the current date and time
Creates and returns a date based on a year and a number of days value
Creates and returns a time based on an hour, minute, and second value
Returns the microsecond part of a time/datetime
Returns the minute part of a time/datetime
Returns the month part for a given date
Returns the name of the month for a given date
Returns the current date and time
Adds a specified number of months to a period
Returns the difference between two periods
Returns the quarter of the year for a given date value
Returns the seconds part of a time/datetime
Returns a time value based on the specified seconds
Returns a date based on a string and a format
Subtracts a time/date interval from a date and then returns the date
Subtracts a time interval from a datetime and then returns the time/datetime
Returns the current date and time
Extracts the time part from a given time/datetime
Formats a time by a specified format
Converts a time value into seconds
Returns the difference between two time/datetime expressions
Returns a datetime value based on a date or datetime value
Returns the number of days between a date and date "0000-00-00"
Returns the week number for a given date
Returns the weekday number for a given date
Returns the week number for a given date
Returns the year part for a given date
Returns the year and week number for a given date

MySQL Advanced Functions

Function Description
Returns a binary representation of a number
Converts a value to a binary string
Goes through conditions and return a value when the first condition is met
Converts a value (of any type) into a specified datatype
Returns the first non-null value in a list
Returns the unique connection ID for the current connection
Converts a number from one numeric base system to another
Converts a value into the specified datatype or character set
Returns the user name and host name for the MySQL account that the server used to authenticate the current client
Returns the name of the current database
Returns a value if a condition is TRUE, or another value if a condition is FALSE
Return a specified value if the expression is NULL, otherwise return the expression
Returns 1 or 0 depending on whether an expression is NULL
Returns the AUTO_INCREMENT id of the last row that has been inserted or updated in a table
Compares two expressions and returns NULL if they are equal. Otherwise, the first expression is returned
Returns the current MySQL user name and host name
Returns the current MySQL user name and host name
Returns the current MySQL user name and host name
Returns the current version of the MySQL database


Login
ADS CODE