DISQUS

Eddie Awad’s Blog: SYS_CONTEXT in Oracle

  • Eddie Awad · 4 years ago
    There is a similar function called `USERENV`. But based on the [documentation](http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions162a.htm#1019148):

    USERENV is a legacy function that is retained for backward compatibility. Oracle Corporation recommends that you use the SYS_CONTEXT function with the built-in USERENV namespace for current functionality
  • Robert Vollman · 4 years ago
    Yes!

    We're on the same page. I discovered this handy thing around the same time:

    http://thinkoracle.blogspot.com/2005/07/which-i...

    Very handy!
  • SIVASANKARAN · 3 years ago

    Execellent ... It is veryful for me.

  • Pete Johnson · 2 years ago

    Hi All


    I have a database on which users can execute queries. To ensure they cant view each others information I want to execute this query first:
    dbms_session.set_context('usernameParam', 'username', username);
    I then want to create views that look like this:
    CREATE OR REPLACE VIEW "MyView" AS SELECT * FROM "DB"."MyTable"
    WHERE "Username" = SYS_CONTEXT('usernameParam', 'username')
    /
    I then want my clients to use the views instead of tables.


    I am doing this using Java. I get a database connection. Using that connection I execute the set_context query. I am wandering, how thread safe is this? If 2 clients at the same time execute a query is it possible that the set_context will be execute in the wrong order and clients see each others information or does the set_context apply only to the current connection even thought the same username is used to connect to the database?