How to reset the State of package variables in all sessions connected (without requiring a disconnection and a connect) if they are reset in one of connected sessions.


Hi people,
Need help, the example requires that the value of packet data 'g_var' must be updated in the session/s connected everywhere without the session/s to be disconnected and reconnected.
Here's the scenario:

I created a table my_table having the pair name / value.
A variable with global package "g_var' in his body and a get accessor method to access g_var variable from the outside world.
This variable g_var is initialized within the block of the entry into force of the package and retrieves the current value of the variable from my_table.
When I update the value in the table a trigger on my_table would reset the State of the package and therefore g_var to the most recent value in the same session
All is well so far since the change in value is reflected in the current session, but if I've already connected session/s
and I'm trying to retrieve the value of "g_var", it is not updated in already connected sessions and remains the same before the update.
Can U help please how can I update this value in a session/s connected without having to disconnect and reconnect.
because if I disconnect and reconect the existing sessions, it seems to show the updated value.

Thanks in advance.

Kind regards
Gaurav Rajput

Here are the Scripts:


drop table my_table;
create table my_table
(
my_variable_name varchar2 (100),
number of my_variable_value
);

create or replace package my_package as
Function get_g_var return number;
end my_package;
/

create or replace package body my_package as
number of g_var;

Function get_g_var return number is
Start
Return g_var;
exception
while others then
lift;
end get_g_var;

procedure init (my_passed_name varchar2) is
Start
Select my_variable_value in the g_var from my_table where my_variable_name = my_passed_name;
exception
while others then
raise_application_error (-20004, "I got an error during Init");
end init;

Start
init ('$'); -This is a call to time when the package is loaded into the memory of session
exception
while others then
raise_application_error (-20003, 'Error in my_package');
end my_pACkage;

/
create or replace TRIGGER my_trigger
BEFORE DELETE OR UPDATE
ON my_table
FOR EACH LINE
declare
number of my_ret;
Start
DBMS_SESSION.modify_package_state (DBMS_SESSION. RESET);
exception
while others then
lift;
end my_trigger;

/

-It is initially set to null
insert into my_table values ('DOLLAR', 62);
commit;

-test value for first time to package loading (62 views)
Select * from my_table;

Set serveroutput on

declare
my_variable varchar2 (100);
BEGIN
my_variable: = my_package.get_g_var;
dbms_output.put_line ($my_var);
END;

-run the same block of end to start in another session it shows 62. All is well so far
-check if the value after the update in the same session (shows 38), also check in another before the connected session as well (shows 62 and not 38)
Update my_table set my_variable_value = 38 where my_variable_name = "DOLLAR";
commit;

Select * from my_table;

Set serveroutput on

-It displays 38 in this session, but there in an already connected session 62 and only after you log out shows 38
declare
my_variable varchar2 (100);
BEGIN
-my_variable: = my_package.g_var;
my_variable: = my_package.get_g_var;
dbms_output.put_line ($my_var);
END;

Package variables are stored in the private memory (PGA). The value is not visible in the session. A package variable is therefore not approach appropriate to your problem. You can look at in the context of the Application, as Solomon has said.

http://docs.Oracle.com/CD/B28359_01/network.111/B28531/app_context.htm#CIHFJHCG

Tags: Database

Similar Questions

Maybe you are looking for

  • Satellite C50-A483 and Win8.1 - quality of the Webcam is very low

    Hi friends, Yesterday, I bought a new laptop Toshiba Satellite C50-A483, single language 8.1 for Windows, 64-bit, which I am very disappointed by the results of the webcam, its too fuzzy, there is no options to change the settings for the webcam, pre

  • HP 2000: administrative password or poweron password

    Locked out of password recovery please code is 54305373 thanks

  • Windows 8.1 does not recognize my scanner

    I recently bought a new computer from DEll desktop with Windows 8.1. My printer, HP DEskjet F4180, prints and copies but does not scan.  I tried to install using the original disk and an icon for appeard Center Solution HP on the desktop, but when I

  • USB 6008 - how to display the two position linear pot (mm) and output (volts) in LabVIEW?

    I have a USB-6008. I have a linear potentiometer attached to the USB DAQ. Now I can view the output voltage of pot in LabVIEW through the AI0 on USB DAQ channel. However, I would also like to be able to show the position of the stem of the linear pot

  • Which laptop?

    Hi, I've been through the web site looking for a used laptop, but there is so much of different. I mainly use it for surfing the net, Facebook, emails and the occasional document. I don't play games on it or watch movies. Can anyone recommend that it