SlideShare uma empresa Scribd logo
1 de 27
What is a Function in PL/SQL?
A function are named PL/SQL Block.It is similar to
a procedure. The major difference between a
procedure and a function is, a function must always
return a value, but a procedure may or may not
return a value.
Structure of Function
stored functions 3 sections
1.declaration section-declaration of variables and
constants
2.executable section-pl/sql statements which
perform specific task
3.exception handling section-the error occuring
in executable part can be handled in this section
CREATE [OR REPLACE] FUNCTION function_name
[ (parameter [,parameter]) ]
RETURN return_datatype
IS | AS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [function_name];
CREATE [OR REPLACE] FUNCTION fa(m number)
RETURN number
IS
f number:=1;
BEGIN
for I in 1….m
Loop
F:=f*I;
End loop;
return f;
End;
TwoTypes Functions
Single-row
functions
Multiple-row
functions
Return one result
per row
Return one result
per set of rows
Functions
Single row functions return a single result
per every row. There are different types of
single-row functions.
Conversion
Character
Number
Date
General
Single-row
functions
Character
functions
LOWER
UPPER
INITCAP
CONCAT
SUBSTR
LENGTH
INSTR
LPAD | RPAD
TRIM
REPLACE
Case-manipulation
functions
1) Character or Text Functions: Character functions
accept character input and can return both character
and number values.
Character-manipulation
functions
1.LOWER
The Lower function converts the character values into
lowercase letters
.
2. UPPER
The Upper function converts the character values into
uppercase letters.
3. INITCAP
The Initcap function coverts the first character of each
word into uppercase and the remaining characters into
lowercase.
.
.
Character-manipulation functions
1.CONCAT
The Concat function coverts the first string
with the second string
2. SUBSTR
The Substr function returns specified characters
from character value starting at position m and n
characters long. If you omit n, all characters starting
from position m to the end are returned.
3.LENGTH
The Length function is used to find the number of
characters in a string
4.RPAD
The Rpad function pads the character value left-justified
to a total width of n character positions.
5.TRIM
The Trim function removes the leading or trailing or both
the characters from a string.
6.REPLACE
The Replace function is used to replace a
character with another Character in a string.
2) Numeric Functions:
Numeric functions accept numeric input and return
numeric values.
ROUND
TRUNC
Numeric functions
3) Date Functions:
Date functions operate on DATE.
Date function
MONTHS_BETWEEN
ADD_MONTHS
NEXT_DAY
LAST_DAY
Explicit data
type conversion
Data type conversion
Implicit data type
conversion
4) Conversion Functions:
Conversion functions convert a value from one
datatype to another.
EXAMPLE
sql>create table stu1(
name varchar2(8),
regno varchar2(10)
mark number(6,2),
DOB date
);
Table created.
SQL> desc stu1;
Name Null? Type
----------------------------------------- -------- --------------
NAME VARCHAR2(8)
REGNO VARCHAR2(10)
DOB DATE
Mark NUMBER
SQL> insert into stuu2 values(&name,&regno,&dob,&mark);
Enter value for name: 'xx'
Enter value for regno: '13sms01'
Enter value for dob: '27-apr-2013'
Enter value for mark: 78.23
old 1: insert into stuu2 values(&name,&regno,&dob,&mark)
new 1: insert into stuu2 values('xx','13sms01','27-apr-
2013',78.23)
1 row created.
SQL> /
Enter value for name: 'yy'
Enter value for regno: '13sms02'
Enter value for dob: '24-jan-2012'
Enter value for mark: 89.78
old 1:
insert into stuu2 values(&name,&regno,&dob,&mark)
new 1: insert into stuu2 values('yy','13sms02','24-jan-
2012',89.78)
1 row created.
SQL> select*from stu1;
NAME REGNO DATE MARK
-------- ---------- ----------------- ------------------
xx 13sms01 27-apr-2013 78.23
yy 13sms02 24-jan-2012 89.78
CASE-MANIPULATION FUNCTION
SQL> select
2 lower(name),upper(name),initcap(name) from stu1;
LOWER(NA UPPER(NA INITCAP(
-------- -------- --------
xx XX Xx
yy YY Yy
CHARACTER MANIPULATION FUNCTION
SQL> select concat(name,regno),
substr(regno,3,2),
length(name),
rpad(regno,10,'*')RPAD,
lpad(regno,10,'*')LPAD,
replace(regno,‘sms','ma')"replace”from stu1;;
CONCAT(NAME,REGNO) SUB LENGTH(NAME) RPAD
------------------ -- ------------ ---------- ---------- --------------------
xx13sms01 sm 2 13sms01***
yy13sms02 sm 2 13sms02***
LPAD replace
---------- ----------
***13sms01 13sms01
***13sms02 13sms02
NUMERIC FUNCTIONS
SQL> select round(mark,1),
trunc(mark,1)
from stu1;
ROUND(MARK,1) TRUNC(MARK,1)
------------- -------------
78.2 78
89.3 89
DATE FUNCTION
SQL> select
add_months(dob,2),
last_day(dob)
from stu1;
ADD_MONTH LAST_DAY(
--------- ---------
27-JUN-13 30-APR-13
20-MAR-12 31-JAN-12
27-JUN-13 30-APR-13
24-MAR-12 31-JAN-12
Multiple-Row Functions
Functions that take a collection of values
as input and return a single value. These
functions are known as group functions and
aggregate function.
Types:
1.avg - Returns avg value of a given expression
2.Min - Returns Minimum value of a given expression
3.Max - Returns Maximum value of a given expression.
4.Sum - Returns total or sum of the expr.
5.count-Counts the no of values present in a column.
EXAMPLE
sql>create table stu2(
major varchar2(10),
semester varchar2(10)
noofpapers number(2),
);
Table created.
SQL> desc stu2;
Name Null? Type
----------------------------------------- -------- --------------
MAJOR VARCHAR2(10)
SEMESTER VARCHAR2(10)
NOOFPAPERS NUMBER
SQL> insert into stu2 values(&major,&semester,&noofpapers);
Enter value for name: ‘computer'
Enter value for regno: ‘first’
Enter value for dob: 6
old 1: insert into stuu2 values(&major,&semester,&noofpapers)
new 1: insert into stuu2 values(‘computer’,’first’,6)
1 row created.
SQL> insert into stu2 values(&major,&semester,&noofpapers);
Enter value for name: ‘computer'
Enter value for regno: ‘second’
Enter value for dob: 5
old 1: insert into stuu2 values(&major,&semester,&noofpapers)
new 1: insert into stuu2 values(‘computer’,’second’,5)
1 row created
SQL> insert into stu2
values(&major,&semester,&noofpapers);
Enter value for name: ‘history'
Enter value for regno: ‘first’
Enter value for dob: 6
old 1: insert into stuu2
values(&major,&semester,&noofpapers)
new 1: insert into stuu2 values(‘history’,’first’,6)
1 row created
MULTIPLE ROW FUNCTION
Sql>select major,sum(noofpapers),
count(noofpapers),
avg(noofpapers)
from stu2 group by major;
MAJOR SUM(NOOFPAPERS) COUNT(NOOFPAPERS) AVG(NO
-------- -------- -------- -----------
computer 11 2 5.5
history 6 2 3

Mais conteúdo relacionado

Mais procurados

Mais procurados (18)

Cpp functions
Cpp functionsCpp functions
Cpp functions
 
user defined function
user defined functionuser defined function
user defined function
 
4. function
4. function4. function
4. function
 
M11 operator overloading and type conversion
M11 operator overloading and type conversionM11 operator overloading and type conversion
M11 operator overloading and type conversion
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Oracle - Program with PL/SQL - Lession 01
Oracle - Program with PL/SQL - Lession 01Oracle - Program with PL/SQL - Lession 01
Oracle - Program with PL/SQL - Lession 01
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
Function
Function Function
Function
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLAB
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function in C and C++
Function in C and C++Function in C and C++
Function in C and C++
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
A green solution to solve a race condition problem
A green solution to solve a race condition problemA green solution to solve a race condition problem
A green solution to solve a race condition problem
 
Functions in c
Functions in cFunctions in c
Functions in c
 

Semelhante a Function and types (20)

Sql 3
Sql 3Sql 3
Sql 3
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Les03
Les03Les03
Les03
 
sql functions3.pdf about the function of sql
sql functions3.pdf about the function of sqlsql functions3.pdf about the function of sql
sql functions3.pdf about the function of sql
 
SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Les03[1] Single-Row Functions
Les03[1] Single-Row FunctionsLes03[1] Single-Row Functions
Les03[1] Single-Row Functions
 
Les03.pptx
Les03.pptxLes03.pptx
Les03.pptx
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
sql functions3 (1).pdf
sql functions3 (1).pdfsql functions3 (1).pdf
sql functions3 (1).pdf
 
2 sql - single-row functions
2   sql - single-row functions2   sql - single-row functions
2 sql - single-row functions
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Les03
Les03Les03
Les03
 
Function
FunctionFunction
Function
 
12th.pptx
12th.pptx12th.pptx
12th.pptx
 

Último

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 

Último (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 

Function and types

  • 1. What is a Function in PL/SQL? A function are named PL/SQL Block.It is similar to a procedure. The major difference between a procedure and a function is, a function must always return a value, but a procedure may or may not return a value.
  • 2. Structure of Function stored functions 3 sections 1.declaration section-declaration of variables and constants 2.executable section-pl/sql statements which perform specific task 3.exception handling section-the error occuring in executable part can be handled in this section
  • 3. CREATE [OR REPLACE] FUNCTION function_name [ (parameter [,parameter]) ] RETURN return_datatype IS | AS [declaration_section] BEGIN executable_section [EXCEPTION exception_section] END [function_name];
  • 4. CREATE [OR REPLACE] FUNCTION fa(m number) RETURN number IS f number:=1; BEGIN for I in 1….m Loop F:=f*I; End loop; return f; End;
  • 5. TwoTypes Functions Single-row functions Multiple-row functions Return one result per row Return one result per set of rows Functions
  • 6. Single row functions return a single result per every row. There are different types of single-row functions.
  • 8. Character functions LOWER UPPER INITCAP CONCAT SUBSTR LENGTH INSTR LPAD | RPAD TRIM REPLACE Case-manipulation functions 1) Character or Text Functions: Character functions accept character input and can return both character and number values. Character-manipulation functions
  • 9. 1.LOWER The Lower function converts the character values into lowercase letters . 2. UPPER The Upper function converts the character values into uppercase letters. 3. INITCAP The Initcap function coverts the first character of each word into uppercase and the remaining characters into lowercase. . .
  • 10. Character-manipulation functions 1.CONCAT The Concat function coverts the first string with the second string 2. SUBSTR The Substr function returns specified characters from character value starting at position m and n characters long. If you omit n, all characters starting from position m to the end are returned.
  • 11. 3.LENGTH The Length function is used to find the number of characters in a string 4.RPAD The Rpad function pads the character value left-justified to a total width of n character positions. 5.TRIM The Trim function removes the leading or trailing or both the characters from a string.
  • 12. 6.REPLACE The Replace function is used to replace a character with another Character in a string.
  • 13. 2) Numeric Functions: Numeric functions accept numeric input and return numeric values. ROUND TRUNC Numeric functions
  • 14. 3) Date Functions: Date functions operate on DATE. Date function MONTHS_BETWEEN ADD_MONTHS NEXT_DAY LAST_DAY
  • 15. Explicit data type conversion Data type conversion Implicit data type conversion 4) Conversion Functions: Conversion functions convert a value from one datatype to another.
  • 16. EXAMPLE sql>create table stu1( name varchar2(8), regno varchar2(10) mark number(6,2), DOB date ); Table created. SQL> desc stu1; Name Null? Type ----------------------------------------- -------- -------------- NAME VARCHAR2(8) REGNO VARCHAR2(10) DOB DATE Mark NUMBER
  • 17. SQL> insert into stuu2 values(&name,&regno,&dob,&mark); Enter value for name: 'xx' Enter value for regno: '13sms01' Enter value for dob: '27-apr-2013' Enter value for mark: 78.23 old 1: insert into stuu2 values(&name,&regno,&dob,&mark) new 1: insert into stuu2 values('xx','13sms01','27-apr- 2013',78.23) 1 row created.
  • 18. SQL> / Enter value for name: 'yy' Enter value for regno: '13sms02' Enter value for dob: '24-jan-2012' Enter value for mark: 89.78 old 1: insert into stuu2 values(&name,&regno,&dob,&mark) new 1: insert into stuu2 values('yy','13sms02','24-jan- 2012',89.78) 1 row created.
  • 19. SQL> select*from stu1; NAME REGNO DATE MARK -------- ---------- ----------------- ------------------ xx 13sms01 27-apr-2013 78.23 yy 13sms02 24-jan-2012 89.78 CASE-MANIPULATION FUNCTION SQL> select 2 lower(name),upper(name),initcap(name) from stu1; LOWER(NA UPPER(NA INITCAP( -------- -------- -------- xx XX Xx yy YY Yy
  • 20. CHARACTER MANIPULATION FUNCTION SQL> select concat(name,regno), substr(regno,3,2), length(name), rpad(regno,10,'*')RPAD, lpad(regno,10,'*')LPAD, replace(regno,‘sms','ma')"replace”from stu1;; CONCAT(NAME,REGNO) SUB LENGTH(NAME) RPAD ------------------ -- ------------ ---------- ---------- -------------------- xx13sms01 sm 2 13sms01*** yy13sms02 sm 2 13sms02*** LPAD replace ---------- ---------- ***13sms01 13sms01 ***13sms02 13sms02
  • 21. NUMERIC FUNCTIONS SQL> select round(mark,1), trunc(mark,1) from stu1; ROUND(MARK,1) TRUNC(MARK,1) ------------- ------------- 78.2 78 89.3 89
  • 22. DATE FUNCTION SQL> select add_months(dob,2), last_day(dob) from stu1; ADD_MONTH LAST_DAY( --------- --------- 27-JUN-13 30-APR-13 20-MAR-12 31-JAN-12 27-JUN-13 30-APR-13 24-MAR-12 31-JAN-12
  • 23. Multiple-Row Functions Functions that take a collection of values as input and return a single value. These functions are known as group functions and aggregate function. Types: 1.avg - Returns avg value of a given expression 2.Min - Returns Minimum value of a given expression 3.Max - Returns Maximum value of a given expression. 4.Sum - Returns total or sum of the expr. 5.count-Counts the no of values present in a column.
  • 24. EXAMPLE sql>create table stu2( major varchar2(10), semester varchar2(10) noofpapers number(2), ); Table created. SQL> desc stu2; Name Null? Type ----------------------------------------- -------- -------------- MAJOR VARCHAR2(10) SEMESTER VARCHAR2(10) NOOFPAPERS NUMBER
  • 25. SQL> insert into stu2 values(&major,&semester,&noofpapers); Enter value for name: ‘computer' Enter value for regno: ‘first’ Enter value for dob: 6 old 1: insert into stuu2 values(&major,&semester,&noofpapers) new 1: insert into stuu2 values(‘computer’,’first’,6) 1 row created. SQL> insert into stu2 values(&major,&semester,&noofpapers); Enter value for name: ‘computer' Enter value for regno: ‘second’ Enter value for dob: 5 old 1: insert into stuu2 values(&major,&semester,&noofpapers) new 1: insert into stuu2 values(‘computer’,’second’,5) 1 row created
  • 26. SQL> insert into stu2 values(&major,&semester,&noofpapers); Enter value for name: ‘history' Enter value for regno: ‘first’ Enter value for dob: 6 old 1: insert into stuu2 values(&major,&semester,&noofpapers) new 1: insert into stuu2 values(‘history’,’first’,6) 1 row created
  • 27. MULTIPLE ROW FUNCTION Sql>select major,sum(noofpapers), count(noofpapers), avg(noofpapers) from stu2 group by major; MAJOR SUM(NOOFPAPERS) COUNT(NOOFPAPERS) AVG(NO -------- -------- -------- ----------- computer 11 2 5.5 history 6 2 3