Mega Code Archive

 
Categories / Oracle PLSQL Tutorial / Function Procedure Packages
 

Packages

Packages encapsulate related functionality into one self-contained unit. Packages are typically made up of two components: a specification and a body. The package specification contains information about the package. The package specification lists the available procedures and functions. These are potentially available to all database users. The package specification generally doesn't contain the code. The package body contains the actual code. CREATE OR REPLACE PACKAGE command: SQL> create or replace package pkg_test1   2  as   3      function getArea (i_rad NUMBER) return NUMBER;   4      procedure p_print (i_str1 VARCHAR2 :='hello',   5                         i_str2 VARCHAR2 :='world',   6                         i_end VARCHAR2  :='!' );   7  end;   8  / Package created. SQL> SQL> create or replace package body pkg_test1   2  as   3      function getArea (i_rad NUMBER)return NUMBER   4      is   5          v_pi NUMBER:=3.14;   6      begin   7         return v_pi * (i_rad ** 2);   8      end;   9  10      procedure p_print(i_str1 VARCHAR2 :='hello',  11                        i_str2 VARCHAR2 :='world',  12                        i_end VARCHAR2  :='!' )  13      is  14      begin  15          DBMS_OUTPUT.put_line(i_str1||','||i_str2||i_end);  16      end;  17  end;  18  / Package body created.