Total Pageviews

February 17, 2017

2/17/2017 02:20:00 AM
Oracle plsql


Oracle Package: Package specification:Global Variables 

A magic value is a literal that has special significance in a system. These values might be type codes or validation limits. Your users will tell you that these magic values never change.
Having  25 line items in my profit-and-loss," one will say. "The name of the parent company," swears another, "will always be eBiztechnics.".In this case don't hard these into your program.


PACKAGE config_pkg
IS
   cl_status      CONSTANT VARCHAR2(1) := 'C';
   op_status      CONSTANT VARCHAR2(1) := 'O';
   act_status     CONSTANT VARCHAR2(1) := 'A';
   inact_status   CONSTANT VARCHAR2(1) := 'I';

   min_diff          CONSTANT NUMBER := 1;
   max_diff   CONSTANT NUMBER := 100;

   e_date       CONSTANT DATE := SYSDATE;
   l_date       CONSTANT DATE := ADD_MONTHS (SYSDATE, 120);

END config_pkg;
Using this package, my two IF statements above now become:
IF footing_difference
   BETWEEN config_pkg.min_diff and config_pkg.max_diff
THEN
   xyz;
END IF;

IF cust_status = config_pkg.cl_satus
THEN
   abc;
END IF;

Notice that when you reference a package element you must use dot notation in the format package_name.object_name so the compiler can resolve the reference to the object's name. This is similar to prefacing a reference to a GLOBAL variable in Oracle Forms with the word GLOBAL, as in :GLOBAL.system_name.
If any of my magic values ever change, we need to modify only the assignment to the appropriate constant in the configuration package. we do not need to change a single program module


There is another motivation for writing a package without a body: . If you follow a top-down design process, you start with a general description of an application and gradually decompose into separate functional areas, programs, or individual statements. With the package structure you can immediately translate high-level refinements into code, while at the same time postponing a resolution of the actual implementation of that code. 


0 comments:

Post a Comment