MySQL Built in Functions
MySQL Built in Functions
STRING FUNCTIONS
• LOWER(str)
• UPPER(str)
• LEFT(str,n)
• RIGHT(str,n)
• SUBSTRING(str,m,n)
• LTRIM(str)
• RTRIM(str)
• TRIM()
• LENGTH(str)
• REVERSE(str)
• CONCAT(str1, str2,……)
• CONCAT_WS(separator,str1,str2,……)
1
STRING FUNCTIONS
• LOWER(str): Returns the string with all alphabets changed to lower case.
• UPPER(str): Returns the string with all alphabets changed to upper case.
• LEFT(str,n): Returns the leftmost ‘n’ alphabets from the string. If ‘n’ is zero or
negative then empty string is returned.
• RIGHT(str,n): Returns the rightmost ‘n’ alphabets from the string. If ‘n’ is zero or
negative then empty string is returned.
• SUBSTRING(str,m,n): Returns a substring of ‘n’ characters long from the given
string, starting at position ‘m’. If ‘n’ is not given then all the characters starting
from ‘m’ is returned. If ‘m’ is zero then empty string is returned. If ‘m’ is negative
then position is taken from the end of the string. If ‘n’ is zero or negative then
empty string is returned.
STRING FUNCTIONS
• LOWER(str)
• UPPER(str)
2
STRING FUNCTIONS
• LEFT(str,n)
STRING FUNCTIONS
• RIGHT(str,n)
3
STRING FUNCTIONS
• SUBSTRING(str,m,n)
STRING FUNCTIONS
• LTRIM(str) • RTRIM(str)
4
STRING FUNCTIONS
• TRIM()
STRING FUNCTIONS
• LENGTH()
5
STRING FUNCTIONS
• REVERSE()
STRING FUNCTIONS
• CONCAT(str1,str2,……)
• CONCAT_WS(separator,str1,str2,….)
6
NUMERIC FUNCTIONS
• ABS(x)
• MOD(n,m)
• ROUND(x,d)
• POWER(x,n)
• SQRT(x)
NUMERIC FUNCTIONS
• ABS(x)
• MOD(n,m)
7
NUMERIC FUNCTIONS
• ROUND(x,d)
NUMERIC FUNCTIONS
• POWER(x,n)
• SQRT(x)
8
DATE & TIME FUNCTIONS
• DAY(date)
• MONTH(date)
• YEAR(date)
• DAYNAME(date)
• MONTHNAME(date)
• CURDATE()
• NOW() or SYSDATE()
• TIME(date)
• DATE(date time)
• DAY(date) • DAYNAME(date)
• MONTH(date) • MONTH(date)
• YEAR(date) • YEAR(date)
9
DATE & TIME FUNCTIONS
• TIME(date time)
10