MySQL has many built-in functions.

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


MySQL String Functions

Function

Description

ASCII

Returns the ASCII value for the specific character

CHAR_LENGTH

Returns the length of a string (in characters)

CHARACTER_LENGTH

Returns the length of a string (in characters)

CONCAT

Adds two or more expressions together

CONCAT_WS

Adds two or more expressions together with a separator

FIELD

Returns the index position of a value in a list of values

FIND_IN_SET

Returns the position of a string within a list of strings

FORMAT

Formats a number to a format like "#,###,###.##", rounded to a specified number of decimal places

INSERT

Inserts a string within a string at the specified position and for a certain number of characters

INSTR

Returns the position of the first occurrence of a string in another string

LCASE

Converts a string to lower-case

LEFT

Extracts a number of characters from a string (starting from left)

LENGTH

Returns the length of a string (in bytes)

LOCATE

Returns the position of the first occurrence of a substring in a string

LOWER

Converts a string to lower-case

LPAD

Left-pads a string with another string, to a certain length

LTRIM

Removes leading spaces from a string

MID

Extracts a substring from a string (starting at any position)

POSITION

Returns the position of the first occurrence of a substring in a string

REPEAT

Repeats a string as many times as specified

REPLACE

Replaces all occurrences of a substring within a string, with a new substring

REVERSE

Reverses a string and returns the result

RIGHT

Extracts a number of characters from a string (starting from right)

RPAD

Right-pads a string with another string, to a certain length

RTRIM

Removes trailing spaces from a string

SPACE

Returns a string of the specified number of space characters

STRCMP

Compares two strings

SUBSTR

Extracts a substring from a string (starting at any position)

SUBSTRING

Extracts a substring from a string (starting at any position)

SUBSTRING_INDEX

Returns a substring of a string before a specified number of delimiter occurs

TRIM

Removes leading and trailing spaces from a string

UCASE

Converts a string to upper-case

UPPER

Converts a string to upper-case



MySQL Numeric Functions

Function

Description

ABS

Returns the absolute value of a number

ACOS

Returns the arc cosine of a number

ASIN

Returns the arc sine of a number

ATAN

Returns the arc tangent of one or two numbers

ATAN2

Returns the arc tangent of two numbers

AVG

Returns the average value of an expression

CEIL

Returns the smallest integer value that is >= to a number

CEILING

Returns the smallest integer value that is >= to a number

COS

Returns the cosine of a number

COT

Returns the cotangent of a number

COUNT

Returns the number of records returned by a select query

DEGREES

Converts a value in radians to degrees

DIV

Used for integer division

EXP

Returns e raised to the power of a specified number

FLOOR

Returns the largest integer value that is <= to a number

GREATEST

Returns the greatest value of the list of arguments

LEAST

Returns the smallest value of the list of arguments

LN

Returns the natural logarithm of a number

LOG

Returns the natural logarithm of a number, or the logarithm of a number to a specified base

Login
ADS CODE