-1
ORA-01031: insufficient privileges
ORA-06512: at "SYS.DBMS_SESSION", line 122
ORA-06512: at "C##USER1.CP_UTILS", line 17

this is the package that generates the above error

13:   procedure setTaskId(PARAM_taskId number)
14:   is
15:     LOC_context varchar(30) := CONST_TASK_CTX||SYS_CONTEXT ('USERENV', 'CURRENT_SCHEMA');
16:   begin
17:     dbms_session.set_context( LOC_context, 'TaskId', PARAM_taskId );
18:     dbms_session.set_context( LOC_context, 'ModelId', null );
19:     dbms_session.set_context( LOC_context, 'SqlTrace', null );
20:   end;

how can I fix this error?

2
  • 2
    Did you try grant execute on sys.dbms_session to <executing user> as sysdba?
    – atokpas
    Dec 20, 2017 at 4:00
  • Thank you for reply.Yes I did.But it has the same error. Dec 20, 2017 at 4:07

1 Answer 1

2

A context is bound to a stored program unit for security reasons.

So when you created the context via CREATE CONTEXT (you did create the context?) then you specify what stored program unit is allowed to set the value.

SQL> create context blah using p1;

Context created.

SQL>
SQL> create or replace
  2  procedure p1 is
  3  begin
  4    dbms_session.set_context('BLAH','MYKEY','myvalue');
  5  end;
  6  /

Procedure created.

SQL>
SQL> create or replace
  2  procedure p2 is
  3  begin
  4    dbms_session.set_context('BLAH','MYKEY','myvalue');
  5  end;
  6  /

Procedure created.

SQL>
SQL> exec p1

PL/SQL procedure successfully completed.

SQL> exec p2
BEGIN p2; END;

*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SYS.DBMS_SESSION", line 130
ORA-06512: at "MCDONAC.P2", line 3
ORA-06512: at line 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.