If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Oracle's 8.1 USERENV() equivalent in UDB 7.2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-10-04, 15:55
brunod brunod is offline
Registered User
 
Join Date: Jun 2004
Posts: 9
Question Oracle's 8.1 USERENV() equivalent in UDB 7.2

Hi,

Looking for your help once again...

In Oracle 8.1 there is a function USERENV() which returns information of varchar datatype about the current session. This information can be useful for writing an application specific audit trail table.

The syntax is as follows:

USERENV(option)

In the above, I'm interested in the option 'SESSIONID'. SESSIONID returns the auditing session identifier.

Eg: USERENV('SESSIONID')

In Oracle, the function is used within one of our select statement which is as follows:

SELECT Terminal
FROM v$session
WHERE OSUSER = UserID and
USERENV('SESSIONID') = AUDSID;

The objective of the above select statement is to return the terminal (or computer name) of the machine on which the specified UserID is logged in.

The columns of the Oracle v$session view are as follows:
SADDR, SID, SERIAL#, AUDSID, PADDR, USER#, USERNAME, COMMAND, OWNERID, TADDR, LOCKWAIT, STATUS, SERVER, SCHEMA#, SCHEMANAME, OSUSER, PROCESS, MACHINE, TERMINAL, PROGRAM, TYPE, SQL_ADDRESS, SQL_HASH_VALUE, PREV_SQL_ADDR, PREV_HASH_VALUE, MODULE, MODULE_HASH, ACTION, ACTION_HASH, CLIENT_INFO, FIXED_TABLE_SEQUENCE, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#, LOGON_TIME, LAST_CALL_ET, PDML_ENABLED, FAILOVER_TYPE, FAILOVER_METHOD, FAILED_OVER, RESOURCE_CONSUMER_GROUP, PDML_STATUS, PDDL_STATUS, PQ_STATUS

From this list, I only need the OSUSER and TERMINAL fields. I hope to find a corresponding system table or system view in DB2 UDB v7.2 that would give me the results I'm after.

If you require more information to help me, please say so.

I thank you in advance for your help!

Sincerely,
Bruno Di Lalla
Reply With Quote
  #2 (permalink)  
Old 06-11-04, 12:43
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by brunod
Hi,

Looking for your help once again...

In Oracle 8.1 there is a function USERENV() which returns information of varchar datatype about the current session. This information can be useful for writing an application specific audit trail table.

The syntax is as follows:

USERENV(option)

In the above, I'm interested in the option 'SESSIONID'. SESSIONID returns the auditing session identifier.

Eg: USERENV('SESSIONID')

In Oracle, the function is used within one of our select statement which is as follows:

SELECT Terminal
FROM v$session
WHERE OSUSER = UserID and
USERENV('SESSIONID') = AUDSID;

The objective of the above select statement is to return the terminal (or computer name) of the machine on which the specified UserID is logged in.

The columns of the Oracle v$session view are as follows:
SADDR, SID, SERIAL#, AUDSID, PADDR, USER#, USERNAME, COMMAND, OWNERID, TADDR, LOCKWAIT, STATUS, SERVER, SCHEMA#, SCHEMANAME, OSUSER, PROCESS, MACHINE, TERMINAL, PROGRAM, TYPE, SQL_ADDRESS, SQL_HASH_VALUE, PREV_SQL_ADDR, PREV_HASH_VALUE, MODULE, MODULE_HASH, ACTION, ACTION_HASH, CLIENT_INFO, FIXED_TABLE_SEQUENCE, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#, LOGON_TIME, LAST_CALL_ET, PDML_ENABLED, FAILOVER_TYPE, FAILOVER_METHOD, FAILED_OVER, RESOURCE_CONSUMER_GROUP, PDML_STATUS, PDDL_STATUS, PQ_STATUS

From this list, I only need the OSUSER and TERMINAL fields. I hope to find a corresponding system table or system view in DB2 UDB v7.2 that would give me the results I'm after.

If you require more information to help me, please say so.

I thank you in advance for your help!

Sincerely,
Bruno Di Lalla
DB2 stores the user in a special register, so VALUES(CURRENT USER) will give you the userid.

The new SNAPSHOT* functions might help you, you can check them out in the SQL Ref vol 1.

Specifically, the function SNAPSHOT_APPL(), ie.
db2 "select * from table (sysproc.snapshot_appl('MYDB', -2)) as snap"

The column INBOUND_COMM_ADDRESS should help I hope!
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 06-11-04, 12:51
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
I neglected to mention that this call can be quite expensive...
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On