Oracle PL/SQL - PL SQL Function Procedure Package Packages

Introduction

A package is a container for your code.

It can also contain cursors, types, global variables, and other constructs.

Packages allow you to place functions and procedures in a container that helps manage all the program units.

Demo

SQL>
SQL> create or replace package pkg_test1
  2  as--  w ww.j  a  v  a 2  s.c o  m
  3        function f_getArea_Nr (i_rad_nr NUMBER) return NUMBER;
  4       procedure p_print (i_str1_tx VARCHAR2 :='hello',
  5                                i_str2_tx VARCHAR2 :='world',
  6                                i_end_tx VARCHAR2  :='!' );
  7  end;
  8  /

Package created.
SQL>
SQL> create or replace package body pkg_test1
  2  as
  3        function f_getArea_Nr (i_rad_nr NUMBER)
  4           return NUMBER
  5        is
  6             v_pi_nr NUMBER:=3.14;
  7       begin
  8           return v_pi_nr * (i_rad_nr ** 2);
  9       end;
 10
 11       procedure p_print
 12        (i_str1_tx VARCHAR2 :='hello',
 13         i_str2_tx VARCHAR2 :='world',
 14         i_end_tx VARCHAR2  :='!' ) is
 15       begin
 16             DBMS_OUTPUT.put_line(i_str1_tx||','
 17                                  ||i_str2_tx||i_end_tx);
 18       end;
 19  end;
 20  /

Package body created.
SQL>
SQL>

Here, you created two database objects, a package and a package body.

The package contains only the function header.

This is the visible part of the function and contains all the information that any code accessing the function needs to know.

The actual function code is placed in the package body.

Related Topics