在11g中,Oracle新增了CLIENTID_OVERWRITE事件,使得执行DBMS_APPLICATION_INFO包的SET_CLIENT_INFO信息后,V$SESSION可以自动反应设置结果。
默认情况下,设置了SET_CLIENT_INFO过程后,还要执行DBMS_SESSION的SET_IDENTIFIER过程,才能使得V$SESSION反映设置后的结果:
SQL> SELECT * FROM V$VERSION;
BANNER
--------------------------------------------------------------------------------
Oracle Database11gEnterprise Edition Release11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> SELECT SID, SERIAL#, CLIENT_IDENTIFIER
2 FROM V$SESSION
3 WHERE SID IN (SELECT SID FROM V$MYSTAT);
SID SERIAL# CLIENT_IDENTIFIER
---------- ---------- ----------------------------------------------------------------
243 7966
SQL> EXEC DBMS_APPLICATION_INFO.SET_CLIENT_INFO('TEST')
PL/SQL过程已成功完成。
SQL> SELECT SID, SERIAL#, CLIENT_IDENTIFIER
2 FROM V$SESSION
3 WHERE SID IN (SELECT SID FROM V$MYSTAT);
SID SERIAL# CLIENT_IDENTIFIER
---------- ---------- ----------------------------------------------------------------
243 7966
SQL> VAR STR VARCHAR2(4000)
SQL> EXEC DBMS_APPLICATION_INFO.READ_CLIENT_INFO(:STR)
PL/SQL过程已成功完成。
SQL> PRINT STR
STR
--------------------------------------------------------------------------------------
TEST
SQL> EXEC DBMS_SESSION.SET_IDENTIFIER('TEST')
PL/SQL过程已成功完成。
SQL> SELECT SID, SERIAL#, CLIENT_IDENTIFIER
2 FROM V$SESSION
3 WHERE SID IN (SELECT SID FROM V$MYSTAT);
SID SERIAL# CLIENT_IDENTIFIER
---------- ---------- ----------------------------------------------------------------
243 7966 TEST
利用DBMS_APPLICATION_INFO包设置的客户端标识只能通过这个包的READ_CLIENT_INFO来获取,如果想要设置的结果直接显示在V$SESSION视图中,可以设置EVENTS CLIENTID_OVERWRITE:
SQL> ALTER SESSION SET EVENTS 'CLIENTID_OVERWRITE';
会话已更改。
SQL> EXEC DBMS_APPLICATION_INFO.SET_CLIENT_INFO('TEST_NEW')
PL/SQL过程已成功完成。
SQL> SELECT SID, SERIAL#, CLIENT_IDENTIFIER
2 FROM V$SESSION
3 WHERE SID IN (SELECT SID FROM V$MYSTAT);
SID SERIAL# CLIENT_IDENTIFIER
---------- ---------- ----------------------------------------------------------------
243 7966 TEST_NEW
取消这个事件通过下面的语句:
SQL> ALTER SESSION SET EVENTS 'CLIENTID_OVERWRITE OFF';
会话已更改。
oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html