In MySQL, I can create an access a session variable by using a single @. Example initialization:
set @myVar = true;
Some trigger containing this code:
if (@myVar is not true) then
execute something
What is the equivalent in Oracle 10g?
SQL> EXEC DBMS_SESSION.SET_CONTEXT('CLIENTCONTEXT', 'myvar', 'myvalue');
PL/SQL procedure successfully completed
SQL> SELECT SYS_CONTEXT('CLIENTCONTEXT', 'myvar') FROM dual;
SYS_CONTEXT('CLIENTCONTEXT','M
--------------------------------------------------------------------------------
myvalue
A package global variable would probably do the same trick.
CREATE OR REPLACE PACKAGE foo as
myVar BOOLEAN;
END foo;
CREATE OR REPLACE PACKAGE BODY foo AS
BEGIN
MyVar := true;
END foo;
BEGIN
If foo.myVar THEN
dbms_output.put_line ('MyVar is True');
end if;
END;
An advantage of using the package over SYS_CONTEXT is that you get some encapsulation.
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