I have been programming oracle row-level security using DBMS_RLS for several years, but I have actually skipped creating contexts. I have seen the intermittent recommendations to
CREATE CONTEXT and now I’m trying to pull the trigger.
But I’m not seeing much benefit to a context at session level. I attach a package, but I still have to grant execute on it to any users I want to be able to use it. What am I missing?
As far as I can tell, the only thing that creating the context with the package is that the package can issue
DBMS_SESSION.SET_CONTEXT naming that context. After that a call to
SYS_CONTEXT with that context will get the value set.
SYS_CONTEXT is itself kind of a hack. It only returns a
VARCHAR2 rather than a typed value. Why not just add a function to the same package with the right data type?
Anything I put into the context with the context package can also be available through that same package.
Now, creating a global context seems like it might have benefits sharing across sessions, except that’s not my goal here.