Experiment 5 - Functions in DBMS
Experiment 5 - Functions in DBMS
Aim: Study & Implementation of Numeric, Character, Aggregate Functions and Group
by functions.
Theory :
1] Single Row functions :- A single row function or scalar fun. Returns only one value for
every row queried in the table. Single Row functions are broadly classified as:-
A] Date functions
B] Numeric functions
C] Character functions
D]Conversions functions.
A] Date functions:-
select sysdate from dual;
SYSDATE
27-OCT-21
1] Add_Months
Syntax:-Add_months (d,n)
Where d is date & n represents no. of months.
select add_months('27-oct-21','2') from dual;
ADD_MONTHS('27- OCT-21','2')
27-DEC-21
2] Last_Day
Syntax:-Last_Day(d)
select last_day('27-nov-21') from dual;
LAST_DAY('27- NOV-21')
30-NOV-21
3] Months_between
Syntax:-Months_between(d1,d2)
select months_between('27-oct-21','27-jan-21') from dual;
MONTHS_BETWEEN('27- OCT-21','27-JAN- 21')
9
4] Next_Day
Syntax:-Next_Day(d,day)
Where d represents date & day implies any week day.
select next_day('27-oct-21','tuesday') from dual;
NEXT_DAY('27-OCT-21','TUESDAY')
02-NOV-21
B] Numeric functions:-
Abs=absolute
select abs(-23.201),abs(-34),abs(43) from dual;
ABS(-23.201) ABS(- 34) ABS(43)
23.201 34 43
CEIL(42.78)
43
FLOOR(100.2)
100
POWER(4,2)
16
C] Character Functions:-
1]Lower(char);
select lower('GOOD MORNING') from dual;
LOWER('GOODMORNING')
good morning
2]Upper(char);
select upper('good morning') from dual;
UPPER('GOODMORNING')
GOOD MORNING
D] Conversion Functions:-
1] To_char(d,fmt):-
Where d is date &fmt is the format . This function converts date to a value of varchar2
in a form specified by date format fmt.
SELECT TO_CHAR(SYSDATE, 'DD-MM-YYYY') FROM dual;
TO_CHAR(SYSDATE,'DD- MM-YYYY')
29-10-2021
2]To_Date(char,fmt):-
Where char is character &fmt is format. This function converts varchar2 to a date.
Fmt specifies form of character.
Table Created
A group function returns the result based on the group of rows . These are as follows:-
A] Avg Function:-
This Function return the average of values of the column specified in the argument of
column.
Syntax:-Avg(Col_name);
select avg(salary) from instructor;
AVG(SALARY)
49250
B] Min Functions :-
The function will give the least of all values of the column present in argument.
Syntax:-Min(Col_name);
MIN(SALARY)
35000
C] Max Function :-
To perform an operation which gives the maximum of a set of values it is used.
Syntax:-Max(Col_name);
D] Sum Function:-
Sum Function can be used to obtain the sum of range of values of record set .
Syntax:-Sum(Col_name);
select salary from instructor;
SALARY
40000
60000
62000
35000
Conclusion :
Hence we have studied Numeric, Character, Aggregate Functions and Group by
functions.