如何将任意参数发送到Oracle触发器? [英] How to send arbitrary parameters to Oracle trigger?

查看:239
本文介绍了如何将任意参数发送到Oracle触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目的是向Web应用程序中的当前用户ID等触发器发送额外信息。由于使用了连接池,并且所有连接都使用相同的用户ID,如何将原始Web用户ID传递给触发器?这需要在不触及应用程序代码的情况下实现。它是一个基于java的应用程序。

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? This I need to implement without touching application code. It is a java based application.

John

推荐答案

你可以使用client_identifier会话变量将应用程序用户传递给触发器。

You can use the client_identifier session variable to pass an application user to a trigger.

在连接到数据库之后设置它,如下所示:

Set it after connecting to the database like this:

  CALL dbms_session.set_identifier('<<username>>');

并在触发器中检索它:

  SELECT sys_context('USERENV','CLIENT_IDENTIFIER') INTO username FROM DUAL;

更多信息可以在 Oracle docs

这篇关于如何将任意参数发送到Oracle触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆