SQL functions are pre-defined program to perform specific tasks. These functions can receive values from outside in the form of Parameters and they return one value. SQL groups functions into two major categories:
1) Group Functions:
Those functions that process multiple records to give single record output. Some of the main group functions are:
a) SUM ()
b) AVG ()
c) MAX ()
d) MIN ()
e) COUNT ( * )
2) Row Functions:
Those functions that work on each record and give output for each record. Row functions are further categories into five groups:
a) Number Functions:
Input values are number and return value is number.
b) Character Functions:
Input values or Return value, any one is character.
c) Date Functions:
Input value or Return value, any one is Date.
d) Conversion Functions
Changes data type of Input value without changing the value.
e) Other Functions:
Input values or their data types or return value type are not fixed.
Restriction on Group Function:
· Group Functions are allowed only with SELECT & HAVING clauses
· Group Function can not be combined with Row Functions or Individual Columns
· Group Functions does not consider NULL value records
GROUP BY Clause:
This clause is used to group related records based on a column or set of columns. Group By clause is very useful for Group Functions as it allows the use of Row Functions and Individual Columns with Group Functions.
Syntax:
GROUP BY
HAVING Clause:
This clause is used to put conditions on the group of records. HAVING clause can not be used without GROUP BY clause as groups of records are provided by it. HAVING conditions are same as WHERE clause conditions but it allows the use of group functions directly.
Number Functions:
a) ABS ((n))
Returns absolute (positive) value.
b) SIGN ((n))
Returns 1 if value is positive, -1 if value is negative and 0 if value is zero.
c) POWER ((n),(p))
Returns value raised up to times.
d) MOD ((n),(d))
Returns remainder of division. is divided by .
e) ROUND ((n) [,(d>))
Returns rounded off value up to specified number of decimal digits. If is not defined then no decimal digit.
f) TRUNC ((n), [,(d)])
Same as ROUND function but does not apply rounding off logic when truncating decimal digits.
g) CEIL ((n))
Returns smallest integer but greater than or equal to value.
h) FLOOR ((n))
Returns greatest integer but less than or equal to value
Character Functions:
a) SUBSTR ((string), (start) [,(no.)])
Returns (no.) from (string) starting from (start).
b) LENGTH ((string))
Returns count of characters within the (string).
c) INSTR ((string-1), (string-2))
Returns position of (string-2) within (string-1), if string-2 is not found then zero.
d) UPPER ((string))
Returns the string with alphabets converted into capital letters.
e) LOWER ((string))
Returns the string with alphabets converted into small letters.
f) LTRIM ((string) [,(char)])
Returns the string removing the from the left side of the string. If (charset) is not given then removes all leading spaces.
g) RTRIM ((string) [,(char)])
Returns the string removing the from the right side of the string. If (char) is not given then removes all trailing spaces.
h) LPAD ((string), (output) [,(filler)])
Returns the string within the