Tuesday, August 12, 2008

Global Variables

Introduction to Global Variables:
Global variables in Oracle forms are the variable which are accessible thruout system (or entire runform session) until we erase it. You can declare these global variables anywhere in PL/SQL code (Triggers or Program Units). Main advantage of using global variables is that using global variable is very easy and simple. On the fly you can declare any number of variables. Value of global variable is preserved for whole runform session. In Oracle 10g forms you can store up to 4000 BYTES of CHAR data, while in previous version it was limited to 255 BYTES CHAR only.
Declaration of Global variables Variables:
In Oracle form style of declaring global variable is quite different than normal PL/SQL variables. PL/SQL variable are always declared in Declaration section of PL/SQL code, while you cannot declare global variables in declaration section. Global variables are initialized by assigning value to them.
e.g.
1) Declaring PL/SQL local Variable
declare
cMyName VARCHAR2(30);
begin
cMyName :='James Bond';
........;
..........;
END;

2) Declaring Global variables:
BEGIN
:Global.myName:='James Bond'; -- Globals are prefixed by ':Global.'
.....;
.....;
END;

Remember that DATATYPE for global variable is always CHAR. So if you are assigning DATE, NUMBER data to global variable and reassigning these global values to any other variable having Datatype other than CHAR, there is always overhead of implicit data-type conversion. If you are using global variables heavily in your system then always take care that you erase global variables after use. Since One global variable requires 4000 BYTES size in Oracle 10g Forms and 255 in previous version, your application will consuming too much amount of memory for global variables variables. It reduces performance drastically.
Removing/Erasing Global variables:
You can remove global variable and release its memory by using 'ERASE' Build-in.
ERASE('Global.myName');
Referencing a global variable that has not been initialized through assignment causes a runtime error.

No comments:

Post a Comment