04 SQLFunctions
04 SQLFunctions
*objectives :
*explain & demonstrate use of expressions
*list the type of sql function categories
*explain & demonstrate arithmetic functions
*explain & demonstrate character functions
*explain & demonstrate date functions
*explain & demonstrate other functions
*explain & demonstrate aggregate/group functions
*explain & demonstrate the group by clause
example :
1. list the total salary and pf of all the employees. pf is
calculated as 10% of salary.
column functions
*the functions supported by oracle can be classified
into following categories :
*aggregate/group functions
*arithmetic functions
*character functions
*date functions
*general functions
arithmetic functions
*abs(n)
*mod(m,n)
*sign(n)
*sqrt(n)
*trunc(m,n)
*round(m,n)
character functions
*initcap (string)
*lower (string)
*upper (string)
*lpad (char1,n[,char2])
*rpad(char1, n [,char2])
*trim (leading or trailing or both trim_char from
string_source)
*substr(string, m[,n])
*instr(string, search_char,[ m, n])
*length (string)
*concat(string1, string2)
date functions
*add_months (d1, n)
*greatest(d1, d2,...)
*least(d1,d2,...)
*last_day(d)
*months_between(d1, d2)
*next_day (date, day)
*to_date(char, f)
*to_char(d,f)
date functions
*examples :
1. list the employees who have joined in year 1981.
nvl function
*is used for handling null values
*nvl function helps in substituting a value in place of a null
*example :
1. list salary, commission, gross salary using nvl for all
employees.
2. list the commission received by all the employees.
decode function
*syntax:
aggregate/group functions
*count(col)
*count(*)
*sum(col)
*avg(col)
*min(col)
*max(col)
examples: group functions
1. list the number of employees working in the company.
*syntax:
select <grouped_by_columns, group functions>
from <table_name>
group by <column|expression, ….>;