0% found this document useful (0 votes)
29 views11 pages

3.1 PLSQL PPT Ch3 PDF

Uploaded by

Dun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views11 pages

3.1 PLSQL PPT Ch3 PDF

Uploaded by

Dun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

PL/SQL Tutorial

By (Procedural - Structured Query Language)


Anjali singh

Let’s make coding fun!


Chapter 3
PL/SQL Tutorial
Functions
Let’s make coding fun!
What do we learn in this Chapter?
What is Functions?

What is the difference between


Functions and Store Procedure?

Functions Syntax

Functions Demonstration

HOMEWORK
What is
Functions?

A stored function (also called a user function or user-


defined function) is a set of PL/SQL statements you can call by
name. Stored functions are very similar to procedures, except that
a function returns a value to the environment in which it is called.
User functions can be used as part of a SQL expression.
Stored May or may not return
Procedure value

Functions will surely Stored


return value using OUT
Functions

The function must return a value but in Stored Procedure it is optional. Even a
procedure can return zero or n values. Functions can have only input parameters
for it whereas Procedures can have input or output parameters. Functions can be
called from Procedure whereas Procedures cannot be called from a Function.
Stored Functions Syntax
CREATE OR REPLACE FUNCTIONS Output parameter is a parameter whose
value is passed out of the stored
<function_name> procedure / function module, back to the
(Argument {IN, OUT, IN/OUT }* calling PL/SQL block. An OUT parameter
must be a variable, not a constant.
<Data type> )Return <var> IS,AS It can be found only on the left-hand side
<variable> declaration; of an assignment in the module.
PL/SQL functions can't able to return multiple
<constant> declarations; values,it can return only one (single
BEGIN )values using OUT parameters in their
<PL/SQL subprogram body>; arguments.
EXCEPTION PL/SQL BLOCK>; *IN – parameter will accept a value from user
Return <variable> OUT – Parameter will return value to user
END <function_name>;
Stored Function Demonstration

Table A

COLA COLB
ROW11 20
ROW21 12
Practice Project
STUDENT

ID GRADE NAME MARKS


STD1 1 ALEX 56
STD2 5 ROBIN 67
STD3 2 JOHN 78
Instructions
1. Create a function to find name of students who
scored marks more than 70 and count number of
students whose marks is more than 50.
2. Create a function to calculate average marks of
students.
For more resource , assistance and
questions , please contact
[email protected] Let’s make coding fun!
Conclusion

Stored Trigger
PL/SQL Functions
Procedure

Cursors Demonstration Interview Tips

Let’s make coding fun!


Let’s make coding fun!

You might also like