This SQL Tutorial provides you a summary of some of the most common MySQL Scalar Functions. For this lesson’s exercises, use this link.
MySQL Scalar Functions allow you to perform different calculations on data values. These functions operate on single rows only and produce one result per row. There are different types of Scalar Functions, this tutorial covers the following:
- String functions – functions that perform operations on character values.
- Numeric functions – functions that perform operations on numeric values.
- Date functions – functions that perform operations on date values.
- Conversion functions – functions that convert column data types.
- NULL-related Functions – functions for handling null values.
Note: this tutorial focuses on MySQL Scalar Functions; for more details about Group Functions, use this link.
MySQL String Functions
|
Syntax |
Description |
Function |
|
Returns text strings concatenated |
CONCAT |
|
Returns the location of a substring in a string. |
INSTR |
|
Returns the number of characters of the specified string expression. |
LENGTH |
|
Returns a character string after truncating all trailing blanks. |
RTRIM |
|
Returns a character expression after it removes leading blanks. |
LTRIM |
|
Replaces all occurrences of a specified string value with another string value. |
REPLACE |
|
Returns the reverse order of a string value. |
REVERSE |
|
Returns part of a text. |
SUBSTR |
|
Returns a character expression after converting uppercase character data to lowercase. |
LOWER |
|
Returns a character expression with lowercase character data converted to uppercase. |
UPPER |
|
Returns a string consisting of N spaces |
SPACE |
MySQL Date Functions
| Syntax |
Description |
Function |
|
Returns a specified date with additional time values. |
DATE_ADD |
|
Returns an integer representing the day (day of the month) of the specified date. |
DAYOFMONTH |
|
Returns a date representing the last day of the month for specified date. |
LAST_DAY |
|
Returns the difference between two days, expressed as a value in days. |
DATEDIFF |
|
returns the number of months between two periods. |
PREIOD_DIFF |
|
Returns the current database system date. This value is derived from the operating system of the computer on which the instance of MySQL is running. |
SYSDATE() |
MySQL Numeric Functions
|
Syntax |
Description |
Function |
|
Returns an integer that is less than or equal to the specified numeric expression. |
FLOOR |
|
Returns an integer that is greater than, or equal to, the specified numeric expression. |
CEIL |
|
Returns a numeric value, rounded to the specified length or precision. |
ROUND |
MySQL Conversion Functions
|
Syntax |
Description |
Function |
|
Converts a a date into a string |
DATE_FORMAT |
|
Converts a number into a string |
FORMAT |
|
Used to convert one datatype into another, may be used to convert a string into a number |
CONVERT |
MySQL NULL-Related Functions
|
Syntax |
Description |
Function |
|
Accepts two arguments and returns the first if its not NULL |
IFNULL |