Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

CREATE CONTEXT USING <PROCEDURE>?

Jibba JabbaAug 4 2013 — edited Aug 5 2013

Having learnt about contexts recently I was of the impression that when creating one you must specify the package that will ultimately be used to call DBMS_SESSION.SET_CONTEXT on the context.

I came across an asktom article today in which (by-the-by) he created a context and specified a procedure.

I thought that was not possible. So I tried it out, and it works. So I checked the documentation and it does indeed state that you must specify a package (although of course the existence of the package is not verified at the time that you execute the CREATE CONTEXT statement).

CREATE CONTEXT

CREATE CONTEXT

Purpose

Use the CREATE CONTEXT statement to:

  • Create a namespace for a context (a set of application-defined attributes that validates and secures an application)
  • Associate the namespace with the externally created package that sets the context

...

package

Specify the PL/SQL package that sets or resets the context attributes under the namespace for a user session.

To provide some design flexibility, Oracle Database does not verify the existence of the schema or the validity of the package at the time you create the context.

So, what am I missing here? Is this just "incorrect documentation", or have I misunderstood? Thanks.

drop context CTX1

/

drop procedure someproc

/

create context ctx1 using someproc

/

create or replace procedure someproc(k varchar2,v varchar2) as

begin

    dbms_session.set_context('CTX1',k,v);

end;

/

show errors

begin

    someproc('AAA','BBB');

    dbms_output.put_line('For context ''CTX'', attribute ''AAA'', value = ''' || sys_context('CTX1','AAA') || '''');

end;

/

Output:

SCOTT@ORCL> @C:\Users\J\Documents\SQL\test44.sql

Context dropped.

Procedure dropped.

Context created.

Procedure created.

No errors.

For context 'CTX', attribute 'AAA', value = 'BBB'

PL/SQL procedure successfully completed.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 2 2013
Added on Aug 4 2013
6 comments
995 views