OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.5

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.5
    iconOceanBase Database
    SQL - V 4.2.5
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    CREATE CONTEXT

    Last Updated:2026-04-09 09:38:52  Updated
    share
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples

    folded

    share

    Purpose

    You can use the CREATE CONTEXT statement to create a namespace for a context (a group of application-defined attributes that are used to validate and protect the application) and associate the namespace with the package that is externally created to set this context.

    You can use the DBMS_SESSION.SET_CONTEXT procedure in the specified package to set or reset the context attributes.

    Notice

    To create a context namespace, you must have the CREATE ANY CONTEXT system privilege.

    Syntax

    CREATE [ OR REPLACE ] CONTEXT namespace
    USING [ schema. ] package_name
    [ INITIALIZED { EXTERNALLY | GLOBALLY }
    | ACCESSED GLOBALLY
    ] ;
    

    Parameters

    Parameter
    Description
    OR REPLACE Uses a different package to redefine the existing context namespace.
    namespace The name of the context namespace to be created or modified. Context namespaces are always stored in the schema SYS.
    schema The schema to which the package belongs. If you do not specify this parameter, the current schema is used.
    package_name The name of the PL package that is used to set or reset the context attributes in the namespace of the current session.
    ACCESSED GLOBALLY Specifies that any application context set in the namespace can be accessed in the entire instance. This setting allows multiple sessions to share application attributes.

    Examples

    • Create a context namespace named dev_context.

       obclient> CREATE OR REPLACE CONTEXT dev_context USING SYS.DBMS_SESSION ACCESSED GLOBALLY;
       Query OK, 0 rows affected
      
    • Use the SYS_CONTEXT() function to control data access based on this context. In the following example, the emp_mgmt package defines the deptno attribute as the identifier of the specified department. You can create a view based on the deptno value to restrict access to employee data in the base table.

       obclient> CREATE VIEW dev_emp_view AS
            SELECT * FROM emp
            WHERE deptno = SYS_CONTEXT('dev_context', 'deptno');
       Query OK, 0 rows affected
      

    Previous topic

    COMMENT
    Last

    Next topic

    CREATE DIRECTORY
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples