Let Us Learn Oracle - Part 50 of N [ Sys_Context Function of Oracle 10g ]
Purpose: This function retrives information about Oracle Environment.
Syntax: Sys_Context(Namespace,parameter [,length])
Where,
Namespace => Oracle namespace to be use.If we use 'UserEnv' as the namespace, we can get information about the current Oracle session.
Parameter => Valid attribute for the session
Length => Length of return value in bytes. It is optional
Example1 : Get the current Database Name
SQL> Select Sys_Context('UserEnv','DB_Name') "Current DB Name"
2 From Dual;
Current DB Name
----------------
orcl
Example2 : Get the name of Current User
SQL> Select Sys_Context('UserEnv','Current_User') "Curent User"
2 From Dual;
Curent User
-----------
SCOTT
Example3 : Get the name of host machine
SQL> Select Sys_Context('UserEnv','Host') "Host Machine"
2 From Dual;
Host Machine
---------------------
WORKGROUP\NILADRI-PC
Example4 : Get the date format for the current session
SQL> Select Sys_Context('UserEnv','NLS_Date_Format') "Current Date Format"
2 From Dual;
Current Date Format
-------------------
DD-MON-RR
References :
Hope this was useful.Thanks for reading