首页 » ORACLE 9i-23ai » sql 存储过程中得到用户名

sql 存储过程中得到用户名

到到当SESSION 用户名的方法很多如select user from dual; select username from user_users; SYS_CONTEXT(‘USERENV’,’CURRENT_USER’)等 等

SQL> conn test/test;
Connected.
SQL> create  table test_pro(id int,
2  name varchar2(20),
3  insertdate date);

Table created.

SQL> create or replace procedure p_user
2  is
3  begin
4  insert into test_pro(id,name,insertdate) values(userenv(‘SESSIONID’),user,sysdate);
5  end;
6  /

Procedure created.

SQL> conn system/oracle
Connected.
SQL> create public synonym p_user for test.p_user;

Synonym created.

SQL> exec p_user;

PL/SQL procedure successfully completed.

SQL> select * from test.test_pro;

ID NAME                                     INSERTDATE
———- —————————————- ————–
13000 SYSTEM                                   13-4月 -11

SQL> conn test/test
Connected.
SQL> exec p_user;

PL/SQL procedure successfully completed.

SQL> select * from test_pro;

ID NAME                                     INSERTDATE
———- —————————————- ————–
13000 SYSTEM                                   13-4月 -11
13001 TEST                                     13-4月 -11

SQL>

打赏

目前这篇文章有1条评论(Rss)评论关闭。

  1. Mamie Ropiski | #1
    2011-12-21 at 17:17

    Hey. Is there a reason why this page looks screwed up in Chrome? Anyway a bit of advice, do a second writeup soon!