I was using the following SQL in PostgreSQL to set a local variable
SET LOCAL myKey = 'myValue'
and then I was able to retrieve this value from a trigger for example - in my case I was passing a username and used by a trigger to log it in an audit table when a row was deleted.
current_setting('myKey')
Now, I am trying to achieve something similar in Oracle 19c and one way proposed is the following:
EXEC DBMS_SESSION.SET_CONTEXT('CLIENTCONTEXT', 'myKey', 'myValue');
and then retrieve it like this:
SELECT SYS_CONTEXT('CLIENTCONTEXT', 'myKey') FROM dual;
- Is this the best practice?
- Are there any better alternatives?
- Is this transaction-safe? I am using JDBC and a pool of connections is used.