13.1 Create Data Role
Use the CREATE DATA ROLE command to create a data role in
the database.
Required privilege
The CREATE DATA ROLE system privilege.
Syntax
CREATE [ OR REPLACE ] DATA ROLE [ IF NOT EXISTS ] data_role_name
{ external_role_clause | local_role_clause };
external_role_clause ::=
MAPPED TO 'identifier_string'
local_role_clause ::=
[ { ENABLED | DISABLED } ]
Parameters
| Parameter | Description |
|---|---|
|
|
The name of the data role to be created. |
|
|
The external provider mapping string (for
externally mapped roles only). The supported formats are:
The single-domain restriction noted for
The |
|
|
The option that specifies whether a data role
(that is managed locally in the database) is enabled or
disabled on creation. The default value is
After a data role is granted to an application identity, you
cannot set it to the |
Usage notes and restrictions
- When
IF NOT EXISTSis specified:- If the data role exists, the statement is a no-op. No error is raised.
- If the data role does not exist, it is created.
- When
IF NOT EXISTSis omitted:- If the data role already exists, an error is raised.
- If the data role does not exist, it is created.
- When
OR REPLACEis specified:- If the data role already exists, the options are replaced.
- If the data role does not exist, it is created.
- When
OR REPLACEis omitted:- If the data role already exists, an error is raised.
- If the data role does not exist, it is created.
OR REPLACEandIF NOT EXISTSare mutually exclusive. Using both in the same statement raises the ORA-11541 error.- A data role can map to at most one external application role. Attempting to create a data role with an external identifier string already in use raises an error. The identifier string comparison is case-insensitive.
- You cannot replace a data role that is externally mapped with a data role that is locally managed, or vice versa. The database raises an error if you attempt such a replacement.
- After you grant a data role that is managed locally to an
application identity, only that application can enable it. You cannot grant
that role to other end users or data roles. After a data role is granted to
an application identity, you cannot set it to the
ENABLEDorDISABLEDstate. The database raisesORA-52539if you attempt to do so.
For syntax diagrams and additional details, see CREATE DATA ROLE in Oracle AI Database SQL Language Reference.
Example 13-1 Create a data role for Microsoft Entra ID role
Create a data role employee_role that maps to a
Microsoft Entra ID role called employee.
- Using the role name
only:
CREATE DATA ROLE employee_role MAPPED TO 'AZURE_ROLE=employee'; - Using the application audience and role
name:
CREATE DATA ROLE employee_role MAPPED TO 'AZURE_APP=https://supremo.onmicrosoft.com/2edc9c9f-8e1e-4ade-8a4a-cc286ed1b899:AZURE_ROLE=employee';
The database first checks for the AZURE_APP prefix. If
it is not present, the database matches using AZURE_ROLE alone. The
optional AZURE_APP prefix uses the end-user token's audience
(aud) claim to distinguish between application roles that share
the same name across different application registrations.
Example 13-2 Create a data role for OCI IAM group in an OAuth 2.0 token
Create a data role employee_role for an OCI IAM group
called employee.
CREATE DATA ROLE employee_role MAPPED TO 'IAM_OAUTH_GROUP=employee';
An application identifier prefix is not required for OCI IAM because groups are shared across applications within the same identity domain, and the database can only be configured with a single domain.
Example 13-3 Create a data role for OCI IAM group in an OCI IAM auth token
Create data roles that map to the OCI IAM group information carried in an OCI IAM auth token. Use this mapping form for any deployment that connects end users to the database with OCI IAM auth tokens.
-- Group in the default domain. The domain prefix is optional.
CREATE DATA ROLE employee_role
MAPPED TO 'IAM_GROUP_NAME=employee';
-- The same group, with an explicit default-domain prefix.
CREATE DATA ROLE employee_role
MAPPED TO 'IAM_GROUP_NAME=default/employee';
-- Group in a non-default identity domain.
CREATE DATA ROLE sales_employee_role
MAPPED TO 'IAM_GROUP_NAME=sales/employee';
Example 13-4 Create data role that is managed locally in the database
Create a data role, it_support_role, with default
settings.
CREATE DATA ROLE it_support_role;
Example 13-5 Create a data role as disabled
Create a data role (that is managed locally in the database) in the disabled state.
CREATE DATA ROLE temp_role DISABLED;