2. Procedures
A procedure is a block of statements
enclosed by some declaration statement with
control blocks and a matching declaration.
All executable statements is must be written
by some procedure.
3. Why to Create a Procedure
It allow you to break your program into discrete logical
units, each of which can be debug more easily than an
entire program without procedures.
It can also use as a building block for other programs.
If you have code that performs the same task in
different places, you can write the task once as a
procedure and then call it from different places in your
code.
4. Types of Sub Procedure
General Procedure It tells the application how
to perform a specific task. It may invoke
another application (function).
Event Procedure Event procedures execute in
response to an event raised by user action or by
an occurrence in a program such as click event
of an object.
5. Function
A Function is a series of statements enclosed by the
certain module (of that system) and End Function
statements.
The Function procedure performs a task and then returns
control to the calling code. When it returns control, it
also may return a value to the calling module.
6. Parts of a Function
A Function has these parts:
Name Anything you like as long as it starts with a letter and
contains only letters numbers and underscores. (without any
space).
Argument List a list of the items of data that the function
needs.
Return Type if the type is Function this tells the compiler
what kind of thing will be returned, for instance, single row or
multi-row , group by etc.
Body all the statements that do the work is as sub procedure.
7. Passing by value (By Value): The procedure gets a copy
of the actual value of the argument.
function (number x)
Passing by reference (By Reference): The procedure
gets access to the argument's actual memory address.
function (number & x )
When a by reference parameter is used, the value of the
passed argument can be permanently changed by the
procedure.
8. Example of Procedure
declare
a number;
b number;
c number;
begin
a:=&a;
b:=&b;
c:=a+b;
dbms_output.put_line('a+b:');
dbms_output.put_line(c);
end;/
9. Example of Function Procedure
Some of the commonly used aggregate functions are :
• SUM
• COUNT
• AVG
• MIN
• MAX
declare
c number;
begin
select avg(sal) into c from EMPLOYEE;
dbms_output.put_line(c);
end;
/
10. Bibliography
• guidance from teachers
•internet
•books and other friends
This is presented to you by:
Avishek Chatterjee & Aatish Kumar Upaddhay