Packaging PL/SQL Subprograms Together. Oracle Release 2 (9.2)
تبلیغات
تبلیغات
Packaging PL/SQL Subprograms Together
Packaging PL/SQL Subprograms Together
You can group logically related subprograms in a package, which is stored in the database. That way, the subprograms can be shared by many applications. The subprogram specs go in the package spec, and the subprogram bodies go in the package body, where they are invisible to applications. Thus, packages allow you to hide implementation details. An example follows:
CREATE PACKAGE emp_actions AS -- package spec
PROCEDURE hire_employee (emp_id INTEGER, name VARCHAR2, ...);
PROCEDURE fire_employee (emp_id INTEGER);
PROCEDURE raise_salary (emp_id INTEGER, amount REAL);
...
END emp_actions;
CREATE PACKAGE BODY emp_actions AS -- package body
PROCEDURE hire_employee (emp_id INTEGER, name VARCHAR2, ...) IS
BEGIN
...
INSERT INTO emp VALUES (emp_id, name, ...);
END hire_employee;
PROCEDURE fire_employee (emp_id INTEGER) IS
BEGIN
DELETE FROM emp WHERE empno = emp_id;
END fire_employee;
PROCEDURE raise_salary (emp_id INTEGER, amount REAL) IS
BEGIN
UPDATE emp SET sal = sal + amount WHERE empno = emp_id;
END raise_salary;
...
END emp_actions;
You can define subprograms in a package body without declaring their specs in the package spec. However, such subprograms can be called only from inside the package. For more information about packages, see
PL/SQL Subprograms
8-11
دانلود
تبلیغات