How to Use the SYS_CONTEXT Function

  • google plus

In Brief...

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 a 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).

Take our Advanced Oracle SQL Queries course for free.

See the Course Outline and Register

Instructions

To learn how to use the SYS_CONTEXT function in Oracle, follow these steps:

  1. 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.
  2. You can display the user name by executing the following SQL select statement:
    Display current user
    .
  3. To learn the database name, enter the following:
    Display database name
  4. The HR schema has been granted the Resource role. We can confirm this fact as shown below:
    Verify Resource role
    The response from the function is TRUE.

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, XML, Windows, Java, Adobe, HTML5, JavaScript, Angular, and much more. Check out our complete course catalog.

Categories

Courses

Author: Stephen Withrow

Stephen has over 30 years' experience in training, development, and consulting in a variety of technology areas including Java, C, C++, XML, JavaScript, AJAX, Tomcat, JBoss, Oracle, and DB2. His background includes design and implementation of business solutions on client/server, Web, and enterprise platforms. Stephen is a published writer in both technical and non-technical endeavors. Stephen received an undergraduate degree in Computer Science and Physics from Florida State University.

Discuss