The purpose is to send extra information to triggers like current user id from a web application. Since a connection pool is used, and same user id is used for all connections how do I pass the original web user id to trigger? It is a java based application.
If you can't touch the application code and the application itself does not pass this information to the database already, you're at an impasse. The only way to make that information available to back-end code is for the middle tier to pass it in.
Oracle provides a number of ways for applications to pass information from the middle-tier to the back end but the application has to be built to take advantage of them. The DBMS_APPLICATION_INFO
package, for example, has a set_client_info
procedure that allows the middle tier to pass in the name of the middle tier user that your back end trigger could query. You can also use Oracle contexts if you want a more general mechanism. Either of these approaches, however, realistically require that the Java application be written to pass this information to the back-end when connections are retrieved from the connection pool.
You can make use of proxy authentication to identify the users even with a ConnectionPool.
An example:
me@XE> @man proxy
[ P R O X Y A U T H E N T I C A T I O N ]
drop user application_user
drop user end_user
-- let's create the application user which all users
-- need to connect through.
-- This user is meant as the middle-tier-user in a
-- multi-tier setup.
create user application_user identified by application_user
-- create an end-user
create user end_user identified by end_user
quota unlimited on users
grant create session, create table to end_user
-- this is the clause to grant access to end_user.
alter user end_user grant connect through application_user
-- now, we can connect WITHOUT PASSWORD!
@connect application_user[end_user]/application_user
-- this should display "END_USER"
select user from dual
-- this should display "APPLICATION_USER"
column proxy_user format a30
select sys_context('userenv', 'proxy_user') proxy_user from dual
http://blogs.oracle.com/jheadstart/entry/using_proxy_authentication
来源:https://stackoverflow.com/questions/8494421/how-to-send-parameters-to-trigger-in-oracle