I am trying to use sys.dbms_session.set_context in one of my stored procedures, but I am getting the following error:
ORA-01031: insufficient privileges
My issue is that I cannot use it in my stored procedure, however...I am getting the same error (Insufficient privileges) when I execute it connected as a user that has execute privileges (and sysdba privileges). Here is the code:
PROCEDURE set_my_env (p_attribute IN VARCHAR2,p_value IN VARCHAR2)
IS
l_namespace VARCHAR2 (30) := 'MY_ENV';
l_attribute VARCHAR2 (30) := NULL;
l_value VARCHAR2 (4000) := NULL;
BEGIN
l_attribute := p_attribute;
l_value := p_value;
DBMS_OUTPUT.PUT_LINE('NAMESPACE: ' || l_namespace);
DBMS_OUTPUT.PUT_LINE('Attribute: ' || l_attribute);
DBMS_OUTPUT.PUT_LINE('value: ' || l_value);
DBMS_SESSION.set_context (l_namespace, l_attribute, l_value);
END set_my_env;
When I execute this code as the non-sysdba user (but it has execute privs), I get the insufficient privileges error.
Thanks in advance.
DBMS_SESSIONis a built-in package, it is installed along with the database installation, is valid and ready to use. Why would you want to compile it (especially connected as some ordinary user)?Anyway, back to your question: how come other users can't compile it? Because it belongs to someone else. SYS. Granting
executeprivilege means that you can use it, not compile it.In order to be able to compile someone else's procedures (packages, whatever), you need to be granted
alter any proceduresystem privilege. However, that doesn't include SYS-owned objects. In order to recompile those, you have to connectas sysdba.If you want to make it (
dbms_session) work, here's how: connected asSYS, grant required privileges to user (scottin my example):Now, connect as
scott; this still won't work:What you have to do is to create a package you'll use for your context business, and create context which uses that package. This is a simplified version, you'd use something smarter:
Now we're ready!
Right; now it works as expected.