What is Package? What
are the benefits? How to create /used package:-
Package are named PL/SQL Blocks and data base schema object
Package stored into database schema permanently.
Package complied and stored as a database object.
Package can be referenced or reused by your program.
IN SIMPLE WAY
Package is collection of Procedure, Function, Cursor, Type and
Variable.
Related of function and procedure are grouping in single
unit that is called Package.
Benefits of Package:-
1.
Package support to overloading.
2.
Package support to hidden.
3.
Easy to manage.
4.
Improve performance.
Components of Packages
PL/SQL package has two components.
1.
Package Specification
2.
Package Body
Package Specification:-
Package specification collection of declaration of all the
public variables, cursors, objects, procedures, functions, and exception
Or
Package specification contain of declaration:-
1.
Declaration of procedure.
2.
Declaration of function.
3.
Declaration of Variables
4.
Declaration of Cursor.
Package Body:-
Package body is containing of definitions:-
1.
Procedure definition
2.
Function definition
3.
Cursor definition
Package specification example:-
CREATE OR REPLACE package APPS.TECHNICAL_ISRAR_PKG
is
function F_ISRAR RETURN VARCHAR2;
PROCEDURE PROC_EMP (A NUMBER, B VARCHAR2 ,C VARCHAR2);
END TECHNICAL_ISRAR_PKG;
/
Package body example:-
CREATE OR REPLACE PACKAGE BODY APPS.TECHNICAL_ISRAR_PKG
IS
FUNCTION F_ISRAR RETURN VARCHAR2
IS
BEGIN
RETURN 'techisrar.blogspot.com';
END F_ISRAR;
PROCEDURE proc_emp (A NUMBER, B VARCHAR2,C VARCHAR2)
IS
BEGIN
INSERT INTO EMP (EMPNO, ENAME ,SAL) VALUES (A,B, C);
END PROC_EMP;
END TECHNICAL_ISRAR_PKG;
/
Note:- EMP IS Table Name
SELECT * FROM EMP
OUTPUT
EXECUTE THE FUNCTION
BEGIN
DBMS_OUTPUT.PUT_LINE(TECHNICAL_ISRAR_PKG.F_ISRAR);
END;
Output with screenshot
2. EXECUTE THE PROCEDURE
BEGIN
TECHNICAL_ISRAR_PKG.PROC_EMP(555,'TECHISRAR','DELHI');
END;
No comments:
Post a Comment