Definition:
In any programming language global variables play an important role in making data exchange and data persistence possible. Similarly, Oracle Forms also support Global variables.
Global variables in Oracle Forms always store the data as character of up to 255 for all kinds of usages. In case you want to use a numeric value for global variable then remember that Oracle will convert it to character, therefore value needs to be converted to number for usage.
Declaration:
Declaration of global variables is done through initialization, if used directly without initialization results in an error. In Oracle Forms 10g storage size for global variables in 4000 bytes. In order to use global variables in Oracle Forms following two methods are available:
Method # 1:
First method available is to use the “:global” keyword, in following example “my_blog” is the variable that we want to declare as global variable and “hasanjawaid.blogspot.com” is the value we wish to assign.
1
| : global .my_blog := 'hasanjawaid.blogspot.com' ; |
Method # 2:
Second method available is to use the “DEFAULT_VALUE”, in following example “my_blog” is the variable that we want to declare as global variable and “hasanjawaid.blogspot.com” is the value we wish to assign.
1
| default_value( 'hasanjawaid.blogspot.com' , 'global.my_blog' ); |
For Numeric values:
Since Oracle converts the value to character therefore In both methods if numeric value is needed following methods can be used.
1
| : GLOBAL .ur_globalvar := TO_CHAR(15); |
or
1
| : GLOBAL .ur_globalvar:= '15' ; |
or following but numeric values will be converted to character by oracle.
1
| : GLOBAL .ur_globalvar := 15; |
Usage:
After declaration, global variables can be used in the form as normal variables in messages or assignments. see following examples:
In messages:
1
| message( 'My blog is ' || : global .my_blog); |
In assignments:
1
| v_blog_value := : global .my_blog; |
Disposing Global Variables:
To destroy a global variable and release its memory, use the ERASE built-in procedure:
1
| Erase( 'GLOBAL.my_var' ); |
No comments:
Post a Comment