Oracle Application Context

Source: Internet
Author: User
Tags dedicated server

Application Context is a group of name-value pairs in the memory. application context belongs to a namespace ).

You can only use one custom procedure to call dbms_session.set_context to set the value of application context. You can use sys_context (<namespace >,< name>) to obtain the value of an application context.

Application context is divided into three types:

 

  • Dabase session-based application context, also known as local application context.
  • Global application context
  • Client session-based application context. It is usually used by OCI and stored in the client memory, instead of the Oracle server, which is also managed by the OCI program.

Local application context is stored in UGA, dedicated server mode, UGA in PGA, shared server mode, and UGA in SGA. Local application context is at the session/server process level. Only this session can be accessed. When the session/server process ends, the lifecycle of the local application context is also over. Oracle VPD http://blog.csdn.net/chncaesar/article/details/18550029, another blog, provides an example of a local application context.

 

 

Global application context is stored in SGA. As long as SGA does not die, global application context always exists. Global application context is often used in cross-session scenarios that are irrelevant to sessions. Dbms_session.set_context has two default values: NULL:

 

  • Username
  • Client_id

 

Username = null, client_id = null. All users can access it.

Username = null, client_id = <client_id>. As long as the session client_id = <client_id>, regardless of username, can access.

Username = <database username>, client_id = null. As long as the session is logged on using the specified oracle schema, it can be accessed regardless of client_id.

Username = <database username>, client_id = <client_id>. It is often used in statless web sessions, such as http.

Username = <non-database username>, client_id = <client_id>. This username will be used by the owner of the database connection pool.

Example 1: application context that all users can access

Create or replace context global_hr_ctx USING hr_ctx_pkg accessed globally;
Create or replace package hr_ctx_pkg
AS
PROCEDURE set_hr_ctx (sec_level IN VARCHAR2 );
PROCEDURE clear_hr_context;
END;
/
Create or replace package body hr_ctx_pkg
AS
PROCEDURE set_hr_ctx (sec_level IN VARCHAR2)
AS
BEGIN
DBMS_SESSION.SET_CONTEXT (
<Strong> namespace => 'Global _ hr_ctx ',
Attribute => 'job _ role ',
Value => sec_level); </strong>
END set_hr_ctx;

PROCEDURE clear_hr_context
AS
BEGIN
DBMS_SESSION.CLEAR_CONTEXT ('Global _ hr_ctx ', 'job _ role ');
END clear_context;
END;
/

Example 2: Cross-session/application, but the application context of the same database schema is used.

Create or replace package hr_ctx_pkg
AS
PROCEDURE set_hr_ctx (sec_level IN VARCHAR2, user_name IN VARCHAR2 );
PROCEDURE clear_hr_context;
END;
/
Create or replace package body hr_ctx_pkg
AS
PROCEDURE set_hr_ctx (sec_level IN VARCHAR2, user_name IN VARCHAR2)
AS
BEGIN
DBMS_SESSION.SET_CONTEXT (
Namespace => 'Global _ hr_ctx ',
Attribute => 'job _ role ',
Value => sec_level,
<Strong> username => user_name); </strong>
END set_hr_ctx;
 
PROCEDURE clear_hr_context
AS
BEGIN
DBMS_SESSION.CLEAR_CONTEXT ('Global _ hr_ctx ');
END clear_context;
END;
/

Both examples provide the clear_hr_context stored procedure. This is because global application context is resident in SGA and needs to be cleared after use to avoid information leakage.

 

USERENV

USERENV is a predefined namespace in Oracle. It contains many common application context.

 

  • CURRENT_USER
  • DB_NAME
  • HOST: client machine name
  • CLIENT_INFO: the client program is used as a count, identifier, etc.

For other application context, see SQL Language Reference.

Detailed illustration of the entire process of VMware + Linux + Oracle 10G RAC

Install Oracle 11gR2 (x64) in CentOS 6.4)

Steps for installing Oracle 11gR2 in vmwarevm

Install Oracle 11g XE R2 In Debian

Steps for installing Oracle 11gR2 in vmwarevm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.