How to Use the SYS_CONTEXT Function
One of the many useful scalar functions in Oracle is the
SYS_CONTEXT function. This function permits you to obtain data from a "namespace". Oracle provides
USERENV namespace that contains data such as your user name and the database to which you are connected. Oracle also provides a
SYS_SESSION_ROLES that can tell you if you have been granted a certain role (a set of privileges).
To learn how to use the
SYS_CONTEXT function in Oracle, follow these steps:
- You'll need to download and install Oracle 12c. The instructions for the setup can be found in the topic . Follow steps 1 through 4 in this topic before proceeding to the next step.
- You can display the user name by executing the following SQL select statement:
- To learn the database name, enter the following:
- The HR schema has been granted the
Resourcerole. We can confirm this fact as shown below:
The response from the function is