两个函数目的都是用来返回数据库及用户信息,具体用法如下:
是否为DBA角色:USERENV('ISDBA')、SYS_CONTEXT('USERENV','ISDBA')
DB的字符集:USERENV('LANGUAGE')、SYS_CONTEXT('USERENV','LANGUAGE')
当前会话标识符:USERENV('SESSIONID')、SYS_CONTEXT('USERENV','SESSIONID')
当前实例:USERENV('INSTANCE')、SYS_CONTEXT('USERENV','INSTANCE')
当前计算机名:USERENV('TERMINAL')、SYS_CONTEXT('USERENV','TERMINAL')
SYS_CONTEXT('USERENV','CURRENT_USER')
SYS_CONTEXT('USERENV','DB_DOMAIN')
SYS_CONTEXT('USERENV','DB_NAME')
SYS_CONTEXT('USERENV','HOST')
SYS_CONTEXT('USERENV','NLS_CURRENCY')
SYS_CONTEXT('USERENV','NLS_CALENDAR')
SYS_CONTEXT('USERENV','NLS_DATE_FORMAT')
SYS_CONTEXT('USERENV','NLS_LANGUAGE')
SYS_CONTEXT('USERENV','NLS_SORT')
例,要取出sid写进日志:
通常的做法:SELECT SID FROM V$MYSTAT WHERE ROWNUM=1
使用userenv:SELECT USERENV('SID') FROM DUAL;