Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert the Oracle user ID into a field 2

Status
Not open for further replies.

dkwong

MIS
Dec 27, 2001
76
CA
I have a field in a table called LAST_USER_ID. I want to populate it with the oracle id/username of the person who creates or updates a record. Is there a reserved constant that stores the id value. How can I get it?
 
There is a function, userenv, that can be used to get the current session id. You can use it to get the Oracle username from v$session. The query would be

select username from v$session
where audsid = (select userenv('sessionid') from dual)
 
Thanks. Can I assign that select statement into a variable and use it in an Insert statement?
 
If simpler, if all you want is the user id is the USER function, which returns the same. You can use it directly to insert the user id into a column:

INSERT INTO your_table (last_user_id)
VALUES (user);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top