Function in SQL
There are two type of function in sql
SQL aggregate function
1) AVG() - Returns the average value
SELECT AVG(column_name) FROM table_name
2) COUNT() - Returns the number of rows
SELECT COUNT(column_name) FROM table_name;
3) FIRST() - Returns the first value
SELECT FIRST(column_name) FROM table_name;
4) LAST() - Returns the last value
SELECT LAST(column_name) FROM table_name;
5) MAX() - Returns the largest value
SELECT MAX(column_name) FROM table_name;
6) MIN() - Returns the smallest value
SELECT MIN(column_name) FROM table_name;
7) SUM() - Returns the sum
SELECT SUM(column_name) FROM table_name;
SQL scalar function
1) UCASE() - Converts a field to upper case
SELECT UCASE(column_name) FROM table_name;
2) LCASE() - Converts a field to lower case
SELECT LCASE(column_name) FROM table_name;
3) MID() - Extract characters from a text field
SELECT MID(column_name,start[,length]) AS some_name FROM table_name;
4) LEN() - Returns the length of a text field
SELECT LEN(column_name) FROM table_name;
5) ROUND() - Rounds a numeric field to the number of decimals specified
SELECT ROUND(column_name,decimals) FROM table_name;
6) NOW() - Returns the current system date and time
SELECT NOW() FROM table_name;
7) FORMAT() - Formats how a field is to be displayed
SELECT FORMAT(column_name,format) FROM table_name;
You can also define your function they are called procedure.
0 Comment(s)