Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define global variable in PL/SQL in Oracle?

Tags:

oracle

plsql

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?

like image 310
Samiul Al Hossaini Avatar asked Mar 31 '15 06:03

Samiul Al Hossaini


People also ask

How do you declare a global variable in Oracle Forms?

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.

Where are global variables stored in Oracle?

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.

Can we declare global variable in package body in Oracle?

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.

What are global variables in package Oracle?

any variable defined outside of a procedure/function is a global variable and maintains its state for the duration of the session.


1 Answers

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;
...
like image 103
Petr Pribyl Avatar answered Sep 28 '22 05:09

Petr Pribyl