How to send arbitrary parameters to Oracle trigger?

前端 未结 3 1175
一个人的身影
一个人的身影 2020-12-14 10:51

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 connectio

3条回答
  •  别那么骄傲
    2020-12-14 11:22

    You can use a package to keep track of the web user:

    create package web_user_pkg is
    
        procedure set_username (p_username varchar2);
    
        function username return varchar2;
    
    end;
    
    create package body web_user_pkg is
    
        g_username varchar2(30);
    
        procedure set_username (p_username varchar2)
        is
        begin
            g_username := p_username;
        end;
    
        function username return varchar2 is
        begin
            return g_username;
        end;
    
    end;
    

    In the web page call web_user_pkg.set_username with the current user's ID before performing any DML or other package calls.

    In the trigger use web_user_pkg.username to get the web user name.

提交回复
热议问题