Sunteți pe pagina 1din 3

WHAT IS THE DIFFERENCE BETWEEN PROCEDURE AND FUNCTION?

PROCEDURE
Procedure is mainly used to perform
one or more specific task.

FUNCTION
Function is mainly used to compute a
value.

Procedure can not be called from the sql Function can be called from the sql
statements .
statements.
A Procedure may or may not return a
value using the OUT parameters.

A Function must return a value.

The RETURN statement of procedure


returns control to the calling program
and cannot return a value.

The RETURN statement of function


returns control to the calling program
and return the result of the function.

Procedure are not considered as


expression.

Functions are considered as


expressions.

HOW WILL YOU CREATE PAKAGES IN PL/SQL.GIVE EXAMPLE


THAT ADDS ONE FUNCTION AND ONE PROCEDURE IN PAKAGES?
PACKAGE SPECIFICATION
The package specification is required when you create a new package.The package
specification lists all the objects which are publicly accessible from other
applications. It declares the types,variables,constants,exceptions,cursors.and
subprograms.The scope of these declarations is local to your database schema and

global to the package.so,the declared objects are accessible from your application
and from anywhere in the package .
To create a package or package specification,use the CREATE PACKAGE
statement ,which you execute interactivelyfrom sql*plus. Here is the syntax:
CREATE [OR REPLACE] PACKAGE package_name {is | as}
Procedure_specification;
Function_specification;
Variable_declaration;
Type_defination;
Exception_declaration;
Cursor_declaration;
END [package_name];

PACKAGE BODY
A package body contains the code that implements the package specification. It
fully defines cursors,procedures and functions declared in the package
specification.Unlike a package specification, the declarative part of a package body
can contain subprogram bodies.
To create a package body, use the CREATE PACKAGE BODY statement, which
you can execute interactively from sql*Plus.here is the syntax:
CREATE [OR REPLACE] PACKAGE BODY package_name {IS|AS}
Procedure_defination;
Function_definition;
Private_variable_declaration;
Private_type_defination;

Cursor_defination;
[BEGIN
Executable_statements;
[EXCEPTION
exception_handlers]]
END [package_name];
The following steps are followed to develop a package:
1. First create the package specification using CREATE PACKAGE statement.
Then we compile the source. The source code is compiled into P Code.
2. Then the package body is created using CREATE PACKAGE BODY
statement within SQL script file. Then we compile this code and check for
error if any.
3. After creating the package specification and its body, you reference the
objects declared in the package specification from outside the package
specification using dot notation.

S-ar putea să vă placă și