JUST DO IT ~

我只想当个程序员

oracle 回话环境变量 userenv ,oracle connetion context 会话环境 连接的会话环境

补充


select userenv('LANGUAGE'),
userenv(
'ISDBA'),
userenv(
'SESSIONID'),
userenv(
'ENTRYID'),
userenv(
'LANG'),
userenv(
'INSTANCE'),
userenv(
'terminal'
 
FROM DUAL 


select userenv('LANGUAGE'),
userenv('ISDBA'),
userenv('SESSIONID'),
userenv('ENTRYID'),
userenv('LANG'),
userenv('INSTANCE'),
userenv('terminal')
 FROM DUAL


USERENV('LANGUAGE')                                  USERENV('ISDBA') USERENV('SESSIONID') USERENV('ENTRYID') USERENV('LANG')                                      USERENV('INSTANCE') USERENV('TERMINAL')
---------------------------------------------------- ---------------- -------------------- ------------------ ---------------------------------------------------- ------------------- -------------------
SIMPLIFIED CHINESE_CHINA.ZHS16GBK                    FALSE                            8745                  0 ZHS                                                                    1 13906B3C2A







select 
SYS_CONTEXT(
'USERENV','TERMINAL') terminal, 
SYS_CONTEXT(
'USERENV','LANGUAGE') language, 
SYS_CONTEXT(
'USERENV','SESSIONID') sessionid, 
SYS_CONTEXT(
'USERENV','INSTANCE') instance, 
SYS_CONTEXT(
'USERENV','ENTRYID') entryid, 
SYS_CONTEXT(
'USERENV','ISDBA') isdba, 
SYS_CONTEXT(
'USERENV','NLS_TERRITORY') nls_territory, 
SYS_CONTEXT(
'USERENV','NLS_CURRENCY') nls_currency, 
SYS_CONTEXT(
'USERENV','NLS_CALENDAR') nls_calendar, 
SYS_CONTEXT(
'USERENV','NLS_DATE_FORMAT') nls_date_format, 
SYS_CONTEXT(
'USERENV','NLS_DATE_LANGUAGE') nls_date_language, 
SYS_CONTEXT(
'USERENV','NLS_SORT') nls_sort, 
SYS_CONTEXT(
'USERENV','CURRENT_USER'current_user
SYS_CONTEXT(
'USERENV','CURRENT_USERID') current_userid, 
SYS_CONTEXT(
'USERENV','SESSION_USER'session_user
SYS_CONTEXT(
'USERENV','SESSION_USERID') session_userid, 
SYS_CONTEXT(
'USERENV','PROXY_USER') proxy_user, 
SYS_CONTEXT(
'USERENV','PROXY_USERID') proxy_userid, 
SYS_CONTEXT(
'USERENV','DB_DOMAIN') db_domain, 
SYS_CONTEXT(
'USERENV','DB_NAME'db_name
SYS_CONTEXT(
'USERENV','HOST') host, 
SYS_CONTEXT(
'USERENV','OS_USER') os_user, 
SYS_CONTEXT(
'USERENV','EXTERNAL_NAME') external_name, 
SYS_CONTEXT(
'USERENV','IP_ADDRESS') ip_address, 
SYS_CONTEXT(
'USERENV','NETWORK_PROTOCOL') network_protocol, 
SYS_CONTEXT(
'USERENV','BG_JOB_ID') bg_job_id, 
SYS_CONTEXT(
'USERENV','FG_JOB_ID') fg_job_id, 
SYS_CONTEXT(
'USERENV','AUTHENTICATION_TYPE') authentication_type, 
SYS_CONTEXT(
'USERENV','AUTHENTICATION_DATA') authentication_data 
from dual 



 

select
SYS_CONTEXT('USERENV','TERMINAL') terminal,
SYS_CONTEXT('USERENV','LANGUAGE') language,
SYS_CONTEXT('USERENV','SESSIONID') sessionid,
SYS_CONTEXT('USERENV','INSTANCE') instance,
SYS_CONTEXT('USERENV','ENTRYID') entryid,
SYS_CONTEXT('USERENV','ISDBA') isdba,
SYS_CONTEXT('USERENV','NLS_TERRITORY') nls_territory,
SYS_CONTEXT('USERENV','NLS_CURRENCY') nls_currency,
SYS_CONTEXT('USERENV','NLS_CALENDAR') nls_calendar,
SYS_CONTEXT('USERENV','NLS_DATE_FORMAT') nls_date_format,
SYS_CONTEXT('USERENV','NLS_DATE_LANGUAGE') nls_date_language,
SYS_CONTEXT('USERENV','NLS_SORT') nls_sort,
SYS_CONTEXT('USERENV','CURRENT_USER') current_user,
SYS_CONTEXT('USERENV','CURRENT_USERID') current_userid,
SYS_CONTEXT('USERENV','SESSION_USER') session_user,
SYS_CONTEXT('USERENV','SESSION_USERID') session_userid,
SYS_CONTEXT('USERENV','PROXY_USER') proxy_user,
SYS_CONTEXT('USERENV','PROXY_USERID') proxy_userid,
SYS_CONTEXT('USERENV','DB_DOMAIN') db_domain,
SYS_CONTEXT('USERENV','DB_NAME') db_name,
SYS_CONTEXT('USERENV','HOST') host,
SYS_CONTEXT('USERENV','OS_USER') os_user,
SYS_CONTEXT('USERENV','EXTERNAL_NAME') external_name,
SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address,
SYS_CONTEXT('USERENV','NETWORK_PROTOCOL') network_protocol,
SYS_CONTEXT('USERENV','BG_JOB_ID') bg_job_id,
SYS_CONTEXT('USERENV','FG_JOB_ID') fg_job_id,
SYS_CONTEXT('USERENV','AUTHENTICATION_TYPE') authentication_type,
SYS_CONTEXT('USERENV','AUTHENTICATION_DATA') authentication_data
from dual




TERMINAL                                                                         LANGUAGE                                                                         SESSIONID                                                                        INSTANCE                                                                         ENTRYID                                                                          ISDBA                                                                            NLS_TERRITORY                                                                    NLS_CURRENCY                                                                     NLS_CALENDAR                                                                     NLS_DATE_FORMAT                                                                  NLS_DATE_LANGUAGE                                                                NLS_SORT                                                                         CURRENT_USER                                                                     CURRENT_USERID                                                                   SESSION_USER                                                                     SESSION_USERID                                                                   PROXY_USER                                                                       PROXY_USERID                                                                     DB_DOMAIN                                                                        DB_NAME                                                                          HOST                                                                             OS_USER                                                                          EXTERNAL_NAME                                                                    IP_ADDRESS                                                                       NETWORK_PROTOCOL                                       
-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --------------------------------------------------------
GDDG-13906B3C2A                                                                  SIMPLIFIED CHINESE_CHINA.ZHS16GBK                                                8745                                                                             1                                                                                                                                                                 FALSE                                                                            CHINA                                                                            ¥                                                                               GREGORIAN                                                                        DD-MON-RR                                                                        SIMPLIFIED CHINESE                                                               BINARY                                                                           IDMP                                                                             61                                                                               IDMP                                                                             61                                                                                                                                                                                                                                                                                                                                  idmp                                                                              -13906B3C2A                                                        GDDG-13906B3C2A\g g                                                              -13906B3C2A\gddg                                                             127.0.0.1                                                                        tcp                                                    










select userenv('language'from dual;



USERENV('LANGUAGE')
----------------------------------------------------
SIMPLIFIED CHINESE_CHINA.ZHS16GBK

SQL>




select * from nls_instance_parameters


SQL> select * from nls_instance_parameters
  2  ;

PARAMETER                                                    VALUE
------------------------------------------------------------ --------------------------------------------------------------------------------
NLS_LANGUAGE                                                 AMERICAN
NLS_TERRITORY                                                AMERICA
NLS_SORT                                                    
NLS_DATE_LANGUAGE                                           
NLS_DATE_FORMAT                                             
NLS_CURRENCY                                                
NLS_NUMERIC_CHARACTERS                                      
NLS_ISO_CURRENCY                                            
NLS_CALENDAR                                                
NLS_TIME_FORMAT                                             
NLS_TIMESTAMP_FORMAT                                        
NLS_TIME_TZ_FORMAT                                          
NLS_TIMESTAMP_TZ_FORMAT                                     
NLS_DUAL_CURRENCY                                           
NLS_COMP                                                    
NLS_LENGTH_SEMANTICS                                         BYTE
NLS_NCHAR_CONV_EXCP                                          FALSE

17 rows selected

SQL>





很久以前我就用过这个sql 

参考
http://blog.tianya.cn/blogger/post_show.asp?BlogID=743282&PostID=8419121


Oracle USERENV和sys_context

作者:hzjwcx 提交日期:2007-2-1 14:19:00



posted on 2008-05-13 13:18 小高 阅读(2180) 评论(1)  编辑  收藏 所属分类: Oracle

评论

# re: oracle 回话环境变量 userenv 2008-08-03 11:13 小高

关于sys_context()函数功能一览

包括取本地ip,服务器端domian/db_name……,还有当前session的信息
后面有使用举例:
AUTHENTICATION_DATA
Data being used to authenticate the login user. For X.503 certificate authenticated sessions, this field returns the context of the certificate in HEX2 format.
256


Note: You can change the return value of the AUTHENTICATION_DATA attribute using the length parameter of the syntax. Values of up to 4000 are accepted. This is the only attribute of USERENV for which Oracle implements such a change.


AUTHENTICATION_TYPE
How the user was authenticated:

DATABASE: username/password authentication

OS: operating system external user authentication

NETWORK: network protocol or ANO authentication

PROXY: OCI proxy connection authentication

30

BG_JOB_ID
Job ID of the current session if it was established by an Oracle background process. Null if the session was not established by a background process.
30

CLIENT_INFO
Returns up to 64 bytes of user session information that can be stored by an application using the DBMS_APPLICATION_INFO package.
64

CURRENT_SCHEMA
Name of the default schema being used in the current schema. This value can be changed during the session with an ALTER SESSION SET CURRENT_SCHEMA statement.
30

CURRENT_SCHEMAID
Identifier of the default schema being used in the current session.
30

CURRENT_USER
The name of the user whose privilege the current session is under.
30

CURRENT_USERID
User ID of the user whose privilege the current session is under
30

DB_DOMAIN
Domain of the database as specified in the DB_DOMAIN initialization parameter.
256

DB_NAME
Name of the database as specified in the DB_NAME initialization parameter
30

ENTRYID
The available auditing entry identifier. You cannot use this option in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to true.
30

EXTERNAL_NAME
External name of the database user. For SSL authenticated sessions using v.503 certificates, this field returns the distinguished name (DN) stored in the user certificate.
256

FG_JOB_ID
Job ID of the current session if it was established by a client foreground process. Null if the session was not established by a foreground process.
30

HOST
Name of the host machine from which the client has connected.
54

INSTANCE
The instance identification number of the current instance.
30

IP_ADDRESS
IP address of the machine from which the client is connected.
30

ISDBA
TRUE if you currently have the DBA role enabled and FALSE if you do not.
30

LANG
The ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.
62

LANGUAGE
The language and territory currently used by your session, along with the database character set, in this form:

language_territory.characterset
52

NETWORK_PROTOCOL
Network protocol being used for communication, as specified in the 'PROTOCOL=protocol' portion of the connect string.
256

NLS_CALENDAR
The current calendar of the current session.
62

NLS_CURRENCY
The currency of the current session.
62

NLS_DATE_FORMAT
The date format for the session.
62

NLS_DATE_LANGUAGE
The language used for expressing dates.
62

NLS_SORT
BINARY or the linguistic sort basis.
62

NLS_TERRITORY
The territory of the current session.
62

OS_USER
Operating system username of the client process that initiated the database session
30

PROXY_USER
Name of the database user who opened the current session on behalf of SESSION_USER.
30

PROXY_USERID
Identifier of the database user who opened the current session on behalf of SESSION_USER.
30

SESSION_USER
Database user name by which the current user is authenticated. This value remains the same throughout the duration of the session.
30

SESSION_USERID
Identifier of the database user name by which the current user is authenticated.
30

SESSIONID
The auditing session identifier. You cannot use this option in distributed SQL statements.
30

TERMINAL
The operating system identifier for the client of the current session. In distributed SQL statements, this option returns the identifier for your local session. In a distributed environment, this is supported only for remote SELECT statements, not for remote INSERT, UPDATE, or DELETE operations. (The return length of this parameter may vary by operating system.)




SQL> SELECT sys_context('USERENV','IP_ADDRESS') FROM DUAL;

SYS_CONTEXT('USERENV','IP_ADDR
--------------------------------------------------------------------------------
10.0.0.177

SQL> SELECT SYS_CONTEXT ('hr_apps', 'group_no') "User Group"
2 FROM DUAL;

User Group
--------------------------------------------------------------------------------

SQL> SELECT sys_context('USERENV','CLIENT_INFO') FROM DUAL;

SYS_CONTEXT('USERENV','CLIENT_
--------------------------------------------------------------------------------

SQL> SELECT sys_context('USERENV','CURRENT_SCHEMA') FROM DUAL;

SYS_CONTEXT('USERENV','CURRENT
--------------------------------------------------------------------------------
IDCBJ

SQL> SELECT sys_context('USERENV','HOST') FROM DUAL;

SYS_CONTEXT('USERENV','HOST')
--------------------------------------------------------------------------------
WORKGROUP\RAINY

SQL> SELECT sys_context('USERENV','AUTHENTICATION_DATA') FROM DUAL;

SYS_CONTEXT('USERENV','AUTHENT
--------------------------------------------------------------------------------

SQL> SELECT sys_context('USERENV','AUTHENTICATION_TYPE') FROM DUAL;

SYS_CONTEXT('USERENV','AUTHENT
--------------------------------------------------------------------------------
DATABASE

SQL> SELECT sys_context('USERENV','DB_DOMAIN') FROM DUAL;

SYS_CONTEXT('USERENV','DB_DOMA
--------------------------------------------------------------------------------
chenyq

SQL> SELECT sys_context('USERENV','DB_NAME') FROM DUAL;

SYS_CONTEXT('USERENV','DB_NAME
--------------------------------------------------------------------------------
ora817

SQL> SELECT SYS_CONTEXT('hr_context', 'org_id') FROM DUAL;

SYS_CONTEXT('HR_CONTEXT','ORG_
--------------------------------------------------------------------------------

SQL>   回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2008年5月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

统计

常用链接

留言簿(3)

随笔分类(352)

收藏夹(19)

关注的blog

手册

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜