How can I define a global variable in PL/SQL which will be available in all functions / procedures / packages?
Is it possible to define?
Or is there any alternate way to do this?
Global variables are not formally declared the way PL/SQL local variables are. Rather, you initialize a global variable the first time you assign a value to it: :GLOBAL. my_var := TO_CHAR(:order.
Oracle stores global variables in memory structures that are part of the Program Global Area. You can read about the PGA in the Memory Architecture chapter of the Oracle Concepts Guide.
The package trans_data needs no body because types, constants, variables, and exceptions do not have an underlying implementation. Such packages let you define global variables--usable by subprograms and database triggers--that persist throughout a session.
any variable defined outside of a procedure/function is a global variable and maintains its state for the duration of the session.
Create new package with your variable in package specification, like this:
CREATE PACKAGE my_public_package IS
my_var Number;
END;
Now you can access variable in any code with access to my_public_package
...
my_public_package.my_var := 10;
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With