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.3.1

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive 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.3.1
    iconOceanBase Database
    SQL - V 4.3.1
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    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

    Activate or deactivate roles for a user

    Last Updated:2026-04-15 08:25:14  Updated
    Share
    What is on this page
    Activate or deactivate roles upon user logon
    Prerequisites
    Considerations
    Application scenarios
    Examples
    Activate or deactivate roles for the current session

    folded

    Share

    You can activate or deactivate roles for a user as needed.

    A user can be granted multiple roles. After granting roles, you can further specify which roles will be active and which ones will be inactive. The user will have all the privileges associated with the active roles, but will not have the privileges associated with the inactive roles.

    Activate or deactivate roles upon user logon

    The Oracle mode of OceanBase Database supports using the DEFAULT ROLE clause in the ALTER USER statement to activate or deactivate roles upon user logon.

    Prerequisites

    • You must have the role to be granted and the GRANT OPTION privilege.

    • You must also have the system privilege UPDATE USER.

    For information about how to view your privileges, see View user privileges. If you do not have the GRANT OPTION privilege, contact the administrator to obtain the privilege. For more information about how to grant privileges to a user, see Grant direct privileges. For more information about how to view your roles, see View roles.

    Considerations

    The DEFAULT ROLE clause takes effect only on the roles that are granted to a user by using the GRANT statement or the roles that are created by users with the CREATE ROLE privilege. The DEFAULT ROLE clause does not take effect on the following roles:

    • Roles that are not granted to a user

      For more information, see Grant a role to a user.

    • Roles that are granted by another role

      For more information, see Grant a role to another role.

    Application scenarios

    The DEFAULT ROLE clause in the ALTER USER statement mainly applies to the following scenarios:

    • Activate one or more roles granted to a user upon user logon

      The SQL syntax is as follows:

      obclient> ALTER USER user_name DEFAULT ROLE role_name;
      
    • Activate all roles granted to a user upon user logon

      The SQL syntax is as follows:

      obclient> ALTER USER user_name DEFAULT ROLE ALL;
      
    • Activate some roles granted to a user upon user logon

      The SQL syntax is as follows:

      obclient> ALTER USER user_name DEFAULT ROLE ALL EXCEPT role_name;
      
    • Deactivate all roles granted to a user upon user logon

      The SQL syntax is as follows:

      obclient>ALTER USER user_name DEFAULT ROLE NONE;
      

    where:

    • role_name specifies the name of the role. Separate multiple role names with commas (,).

    • ALL specifies to activate all roles granted to a user.

    • EXCEPT specifies to activate all roles granted to a user, except for the roles specified in the EXCEPT clause. Separate multiple role names with commas (,).

    • NONE specifies to deactivate all roles granted to a user.

    Examples

    Activate the role1 role granted to a user upon user logon.

    obclient>ALTER USER test DEFAULT ROLE role1;
    

    For more information about the ALTER USER statement, see ALTER USER.

    Activate or deactivate roles for the current session

    The Oracle mode of OceanBase Database supports using the SET ROLE statement to activate or deactivate roles granted to the current logged-on user for the current session.

    Note

    The SET ROLE statement takes effect only for the current session, not subsequent sessions.

    Here are the application scenarios:

    • Activate one or more roles granted to the current logged-on user for the current session

      The SQL syntax is as follows:

      obclient> SET ROLE role_name [ IDENTIFIED BY password ];
      
    • Activate all roles granted to the current logged-on user for the current session

      The SQL syntax is as follows:

      obclient> SET ROLE ALL;
      
    • Activate some roles granted to the current logged-on user for the current session

      The SQL syntax is as follows:

      obclient> SET ROLE ALL EXCEPT role_name;
      
    • Deactivate all roles granted to the current logged-on user for the current session

      The SQL syntax is as follows:

      obclient> SET ROLE NONE;
      

    where:

    • role_name specifies the name of the role. Separate multiple role names with commas (,).

    • IDENTIFIED BY password specifies the password for an active role. If a role has been granted a password upon creation, you must specify the password to activate the role.

      For more information about how to create a role, see Create a role.

    • ALL: specifies to activate all roles granted to the current logged-on user for the current session.

      Notice

      When you activate all roles granted to the current logged-on user for the current session, an error is returned if any of the roles has a password.

    • EXCEPT: specifies to activate all roles granted to the current logged-on user for the current session, except for the roles specified in the EXCEPT clause. Separate multiple role names with commas (,).

    • NONE: specifies to deactivate all roles granted to the current logged-on user for the current session.

    Here are some examples:

    • Activate the role1 role identified by the password ****** for the current session.

      obclient> SET ROLE role1 IDENTIFIED BY ******;
      Query OK, 0 rows affected
      
    • Activate all roles for the current session except for the role2 role.

      obclient> SET ROLE ALL EXCEPT role2;
      Query OK, 0 rows affected
      

    For more information about the SET ROLE statement, see SET ROLE.

    Previous topic

    Grant a role to a user
    Last

    Next topic

    View roles
    Next
    What is on this page
    Activate or deactivate roles upon user logon
    Prerequisites
    Considerations
    Application scenarios
    Examples
    Activate or deactivate roles for the current session