Search This Blog

Total Pageviews

Monday, 26 March 2018

oracle whoami.sql


 oracle whoami.sql?

whoami.sql

oracle 12c 
set linesize 200 pagesize 100 serveroutput on
column "db details" format a100
select
 'db_name: ' ||sys_context('userenv', 'db_name') ||
 ' \cdb:-' ||(select cdb from v$database) ||
 ' \auth_id: ' ||sys_context('userenv', 'authenticated_identity') ||
 ' \user: ' ||sys_context('userenv', 'current_user') ||
 ' \container:' ||nvl(sys_context('userenv', 'con_name'), 'non-cdb') "db details"
 from dual ;

-----


set linesize 200 pagesize 0 serveroutput on
column "db details" format a200
select
'user:\'||sys_context('userenv','session_user')||' session_id:\ '||'current_schema:\ '||sys_context('userenv','current_schema')||' instance_name:\ '||sys_context('userenv','instance_name')||
' database role: '||sys_context('userenv','database_role')||' os user:\ '||sys_context('userenv','os_user')||' client ip address:\ '||sys_context('userenv','ip_address')||' server hostname:\ '||sys_context('userenv','server_host')||' client hostname:\ '||sys_context('userenv','host') "db details"
from dual ;



-- From Web ...

set serveroutput on
begin
dbms_output.put_line('USER: ' ||sys_context('userenv','session_user'));
dbms_output.put_line('SESSION ID: ' ||sys_context('userenv','sid'));
dbms_output.put_line('CURRENT_SCHEMA: ' ||sys_context('userenv','current_schema'));
dbms_output.put_line('INSTANCE NAME: ' ||sys_context('userenv','instance_name'));
dbms_output.put_line('DATABASE ROLE: ' ||sys_context('userenv','database_role'));
dbms_output.put_line('OS USER: ' ||sys_context('userenv','os_user'));
dbms_output.put_line('CLIENT IP ADDRESS: '||sys_context('userenv','ip_address'));
dbms_output.put_line('SERVER HOSTNAME: ' ||sys_context('userenv','server_host'));
dbms_output.put_line('CLIENT HOSTNAME: ' ||sys_context('userenv','host'));
end;
/

No comments:

Oracle DBA

anuj blog Archive