Professional Documents
Culture Documents
Oracle 10g Packages
Oracle 10g Packages
Selvaraj V
Anna University Chennai.
Chennai – 25.
Oracle Packages, Procedures, Functions
So, Merits:
Demerit:
The main demerit is again, the whole package is loaded into memory
whenever any procedure/function is called. If only 20% of the procedures/functions
in the package are used, memory consumption gets high for minimal package usage
Spec : is nothing but is like a header which holds all Procedure/Function declarations
and Global variables, collections etc if used.
Body: body has the actual definition of the stored procedures/Functions. All Data
manipulation is done in the procedures and functions, which are defined in the body.
Eg:
--Spec:
END EX_PACK_001;
/
--Body:
--CODE HERE--
EXCEPTION
--EXCEPTION BLOCK--
END EX_PROC_001;
V_CODE NUMBER;
BEGIN
--CODE HERE
RETURN V_CODE;
EXCEPTION
--EXCEPTION BLOCK--
END EX_FUNC_001;
END EX_PACK_001;
Declare
v_code number;
v_number number;
v_char varchar2(50);
Begin
v_number:=100;
v_char:=Hai;
EX_PACK_001. EX_PROC_001(v_number,v_char,v_code); --
v_code is an OUT parameter
dbms_output.put_line(v_code); --displays data
returned to the OUT param
end;
For eg:
PROCEDURE EX_PROC_001
(
P_NUMBER IN NUMBER,
P_CHAR IN VARCHAR2
);
END EX_PACK_001;
/
b. Differs in datatype of parameters, but same number of parameters
PROCEDURE EX_PROC_001
(
P_CHAR1 IN VARCHAR2,
P_CHAR2 IN VARCHAR2,
P_RET_CODE OUT NUMBER
);
END EX_PACK_001;
/
a. Only function can Return a value (to be precise using the Return keyword)
b. Procedures can use Return keyword but without any value being passed
c. Functions could be used in select statements, provided they doesn’t do any
data manipulation inside and also should not have any OUT, IN OUT parameters.
Create variables inside the body (but outside any procedure or function). All of the
functions/procedures in the package can use the variable, but could not be used
outside
Write the procedures/functions only in the body. That means, do not declare the
procedure/function in the Spec.
Advantage being, we can create global variables or collections and put them in a
package Spec. No need to create any body since there are no procedures/functions.
Eg:
EX_PACK_001.v_records:=1000;