Log on to the trigger (or in the process) to obtain the id of the current Session v $ mystat

Source: Internet
Author: User

Obtain the id of the current session in the login trigger (or during the process) v $ mystat how to obtain the id of the current session in the login trigger ??? Www.2cto.com 1. an error occurred while using UserEnv ('sessionid') in the logon trigger. the logon trigger cannot use v $ session, v $ mystat, (the user even has the dba permission. only the current user name is not enough, because the same user may have multiple connections at the same time. 4. If Dbms_session.UNIQUE_SESSION_ID is used to obtain the unique sequence number, you can obtain information about connecting to the client by matching the current session record in v $ session. In fact, my goal is to obtain a unique identifier for the current session and the information of the client currently connected for later use. Thank you for your attention: triggers, sessions, users, permissions, connections ------------------------- create global temporary table usertype_temp2 (SessionID integer, userid integer, usertype integer) on Commit delete Rows; -- Method 1: insert into usertype_temp2 select sid, 1, 1 from v $ mystat where rownum = 1; insert into usertype_temp2 select sid, 2, 2 from v $ mystat where rownum = 1; insert into usertype_temp2 select sid, 3,3 from v $ mystat where rownum = 1; update usertype_temp2 set sessionid = (select sid from v $ mystat where rownum = 1) -- create or replace trigger usertype_temp2_t before insert on usertype_temp2 for each row begin select sid into: new. sessionid from v $ mystat where rownum = 1; end; -- if the system prompts that v $ mystat cannot be found when a trigger is created, this is a permission issue. insert into usertype_temp2 (userid, usertype) values (); insert into usertype_temp2 (userid, usertype) values (); insert into usertype_temp2 (userid, usertype) values (); -- solution: USER01 @ HUIYI> create or replace procedure t1 is 2 l_sid number; 3 l_serial number; 4 begin 5 select sid, serial # into l_sid, l_serial from sys. v _ $ session where audsid = userenv ('sessionid'); 6 dbms_output.put_line (l_sid); 7 end; 8/warning: the created program contains too many threads. USER01 @ HUIYI> show error PROCEDURE T1 occurs when rows: LINE/col error -------- rows 5/3 PL/SQL: SQL Statement ignored 5/51 PL/SQL: ORA-00942: SYS @ HUIYI> grant select on sys. v _ $ session to user01; permission granting. USER01 @ HUIYI> create or replace procedure t1 is 2 l_sid number; 3 l_serial number; 4 begin 5 select sid, serial # into l_sid, l_serial from sys. v _ $ session where audsid = userenv ('sessionid'); 6 dbms_output.put_line (l_sid); 7 end; 8/A program has been created. USER01 @ HUIYI> exec t1 (); 11 PL/SQL program completed successfully.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.