Skip to Main Content
  • Questions
  • Is there any mechanism to Store list of values in an apex global variable/ or can we declare some global pl/sql variables.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Abdul.

Asked: June 01, 2017 - 6:05 am UTC

Last updated: January 28, 2021 - 9:16 am UTC

Version: Oracle Apex 5.1

Viewed 1000+ times

You Asked

Hi Tom,

I have a requirement where i am using some control parameters in my application (pair of key values) which needs to be stored in an apex global variable so that I can access this values from any where in the application. Is there any section available in the Apex where we can define any global PL/SQL APPLICATION level variable. Can you please tell me how to achieve this in Apex 5.1.


and Connor said...

Options you could explore:

- Application Items

(depends on how many values you have)

- A collection (see apex_collection)

https://docs.oracle.com/database/121/AEAPI/apex_collection.htm#AEAPI531

- a global context variable

https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1578344046713#10171639368004

Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Abdul Rahim, June 02, 2017 - 10:26 am UTC

Hi Tom,

Thanks for the answer. I have a package with some global collection variable is available. I thought of writing an application level process to populate collection in the package which will be triggered after the authentication. But when i checked that collection count in my page, it is showing as zero. Why it is showing like that ?? But If i Select the processing point as on load(before header), the count is showing correctly. The global variables in the package should be persisted across the session rt??
Connor McDonald
June 06, 2017 - 1:46 am UTC

Package global variables are bound to a session not to an instance.

Each *session* will have its *own* set of package global values.

Regarding the Scope of the Package variable

Abdul Rahim, June 06, 2017 - 6:08 am UTC

Hi Tom,

In my Oracle apex application, I have created an application level Process and the name of the process is sample_apex_utility which package and this package will populate an array after the authentication is finished. The structure is given below.
create or replace PACKAGE sample_apex_utility AS
TYPE t_apex_utility_tab_type IS TABLE OF varchar2(100) INDEX BY varchar2(50);
t_apex_utility_tab t_apex_utility_tab_type;
END;

The intension of this package is to store my parameter key and values in the associative array defined in this package
So that I can make use of this parameter key values thought the application in different pages(same seesion). I have read the parameter control values from the table and populated this package array after the authentication is finished.

But I have cheked the value in different pages in the same application, the array has no values. What I understood is whithin an apex session, once we set the package variables, the same values will be accessible in all pages in the same session(same application). So I have set the value after the authentication. But the values is not pestied in other pages in the same session. I checked the array count, it is showing as 0. Could you please suggest why it is happening.

Connor McDonald
June 06, 2017 - 8:29 am UTC

Two different things here:

Same *apex* session is you returning to an existing apex session. But that is not the same as the same *database* session, which typically for apex will be a connection pool. Apex is stateless from the database point of view.

So it works something like this:

- you go to your first apex page
- database session "123" services that request
- you login to apex and hit Submit
- database session "456" services that request
- you now have apex session 47291274

Now you go to a new page.

- database session "345" services that request saying that apex session 47291274 has now moved to page 2 in the application
- you now click on another page
- database session "542" services that request saying that apex session 47291274 has now moved to page 3 in the application

So the database sessions are simply allocated from a pool of available sessions to service your "single" apex session. So the package you populated back in database session 123 is no longer applicable.

Which brings us back to the original answer

Options you could explore:

- Application Items (depends on how many values you have)
- A collection (see apex_collection)

https://docs.oracle.com/database/121/AEAPI/apex_collection.htm#AEAPI531

- a global context variable

https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1578344046713#10171639368004

because these are things that can stored information *across* database sessions.

Abdul Rahim, June 06, 2017 - 9:12 am UTC

Thanks you so much tom. Awsome reply... Really informative. I got the concept clearly.

Out of date

A reader, January 25, 2021 - 11:56 am UTC


Connor McDonald
January 28, 2021 - 9:16 am UTC

In what way?