"A package is a container for other database objects."
A package can hold other database objects such as variables , consatants,cursors,exceptions,procedures,functions and sub-programs.
A package has usually two components, a specification and a body.
A package's specification declares the types (variables of the record type), memory variables, constants, exceptions, cursors, and subprograms that are available for use.
A package's body fully defines cursors, functions, and procedures and thus implements the specification.
Create [or replace] package package_name {is | as} Package_specification End package_name;
create package operation that contains procedure 'add' and function 'sub'.
CREATE OR REPLACE PACKAGE OPERATION IS PROCEDURE ADDITION(A IN NUMBER,B IN NUMBER); FUNCTION SUB(A IN NUMBER,B IN NUMBER)RETURN NUMBER; END OPERATION; /
The body of a package contains the definition of public objects that are declared in the specification.
The body can also contain other object declarations that are private to the package.
The objects declared privately in the package body are not accessible to other objects outside the package.
Unlike package specification, the package body can contain subprogram bodies.
After the package is written, debugged, compiled and stored in the database applications can reference the package's types, call its subprograms, use its cursors, or raise its exceptions.
Create [or replace] package body package_name {is | as} Package_body End package_name;
Create or replace package body OPERATION is PROCEDURE ADDITION(A IN NUMBER,B IN NUMBER) is begin dbms_output.put_line('addtion of two number :'||ADD(A,B)); end; FUNCTION SUB(A IN NUMBER,B IN NUMBER)RETURN NUMBER is ans number(3); begin ans:=A-B; return ans; end; end OPERATION; /
Ask Question