sys_context虽然用的地方不多,但是十分强大,属于oracle的系统函数。归属于STANDARD 包
SQL> select * from v$version ;
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
PL/SQL Release 12.2.0.1.0 - Production 0
CORE 12.2.0.1.0 Production 0
TNS for Linux: Version 12.2.0.1.0 - Production 0
NLSRTL Version 12.2.0.1.0 - Production 0
SQL> select * from v$database ;
SQL> select * from v$thread ;
SQL> select * from gv$instance ;
查找 sys_context 的出处
select *
from dba_source vs
where 1=1
and upper(vs.text) like '%SYS_CONTEXT%'
and vs.name = 'STANDARD'
order by vs.line
;
-- New built-in function SYS_CONTEXT
function SYS_CONTEXT (namespace varchar2, attribute varchar2)
return varchar2;
-- SYS_CONTEXT now has an additional optional parameter
function SYS_CONTEXT(namespace varchar2, attribute varchar2,
newoptional varchar2)
return varchar2;
常用的几个
select SYS_CONTEXT('USERENV','CURRENT_SCHEMA')
from dual
;
select SYS_CONTEXT('USERENV','SESSION_USER')
from dual
;
select SYS_CONTEXT('USERENV','CURRENT_USER')
from dual
;
select SYS_CONTEXT('USERENV','SID')
from dual
;
select SYS_CONTEXT('USERENV','CDB_NAME')
from dual
;
select SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER')
from dual
;
select SYS_CONTEXT('USERENV','CLIENT_INFO')
from dual
;
select SYS_CONTEXT('USERENV','DATABASE_ROLE')
from dual
;
select SYS_CONTEXT('USERENV','DB_DOMAIN')
from dual
;
select SYS_CONTEXT('USERENV','DB_NAME')
from dual
;
select SYS_CONTEXT('USERENV','DB_UNIQUE_NAME')
from dual
;
select SYS_CONTEXT('USERENV','HOST')
from dual
;
select SYS_CONTEXT('USERENV','INSTANCE')
from dual
;
select SYS_CONTEXT('USERENV','INSTANCE_NAME')
from dual
;
select SYS_CONTEXT('USERENV','IP_ADDRESS')
from dual
;
select SYS_CONTEXT('USERENV','ISDBA')
from dual
;
select SYS_CONTEXT('USERENV','LANG')
from dual
;
参考:
IT虾米网
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/3906.html