Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • scripts to take listener.log backup Linux/Unix
  • Index Range Scan Oracle
  • Rman Notes -1 Oracle
  • Jai Shree Ram Oracle
  • Rman Notes -1 Oracle
  • To Find Orphan OS processes. Linux/Unix
  • Composite Index creation tip from Vivek Oracle
  • Oracle Internal Good Websites 1 Oracle
  • find_log_switch.sql Find log switches in graphical manner Oracle
  • before_trunc.sql Before Truncate table needs to execute following: Oracle
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • temp_use.sql diplays usage of temp ts Oracle
  • Sample WW22 listener.ora Oracle
  • sql_plan9i.sql Oracle
  • avail.sh ( find filesystem spae usage) Linux/Unix

get_ratio.sql get the ratio of users from v$session and this uses CASE-WHEN-THEN clause

Posted on 10-May-2008 By Admin No Comments on get_ratio.sql get the ratio of users from v$session and this uses CASE-WHEN-THEN clause

set time on

set timing on

set verify off

select to_char(sysdate, ‘DD-MON-RRRR:HH24:MI’) from dual;

prompt ‘Total distinct users and total user sessions’

select count(distinct username), count(1), round(count(1)/count(distinct username),1 )

from v$session

where username is not null;

prompt ‘Total terminal server distinct users and total user sessions’

select count(distinct username), count(1), round(count(1)/count(distinct username),1 )

from v$session

where username is not null and instr(machine, ‘TS’) != 0;

column osuser format a10

column username format a30

column machine format a30

column program format a40

column sid format 99999999

column serial# format 99999999

column dt1 format a20

compute sum of “TOTAL_SESSIONS” on report

compute sum of “TOTAL_UNIQ_USERS” on report

break on report

set lines 141

set pages 500

select (case

when instr(osuser, ‘live’) != 0 then ‘liveops’

when instr(osuser, ‘neova’) != 0 then ‘neova’

when instr(osuser, ‘alamo’) != 0 then ‘alamo’

when substr(osuser, 1,1)= ‘u’ then ‘uxxxx’

else ‘others’

end ) OS_USER ,

substr(machine, 1, 13) MACHINE,

count(1) “TOTAL_SESSIONS”, count(distinct username) “TOTAL_UNIQ_USERS” ,

round(count(1)/count(distinct username),1) “Ratio”

from v$session

where substr(machine, 1, 13) = ‘FLOWERS_NTTS’

group by (case

when instr(osuser, ‘live’) != 0 then ‘liveops’

when instr(osuser, ‘neova’) != 0 then ‘neova’

when instr(osuser, ‘alamo’) != 0 then ‘alamo’

when substr(osuser, 1,1)= ‘u’ then ‘uxxxx’

else ‘others’

end ), substr(machine, 1, 13)

order by 2;

select (case

when instr(osuser, ‘live’) != 0 then ‘liveops’

when instr(osuser, ‘neova’) != 0 then ‘neova’

when instr(osuser, ‘alamo’) != 0 then ‘alamo’

when substr(osuser, 1,1)= ‘u’ then ‘uxxxx’

else ‘others’

end ) OS_USER ,

substr(machine, 1, 13) MACHINE,

count(1) “TOTAL_SESSIONS”, count(distinct username) “TOTAL_UNIQ_USERS” ,

round(count(1)/count(distinct username),1) “Ratio”

from v$session

where substr(machine, 1, 13) != ‘FLOWERS_NTTS’

and substr(machine, 1, 10) = ‘FLOWERS_NT’

group by (case

when instr(osuser, ‘live’) != 0 then ‘liveops’

when instr(osuser, ‘neova’) != 0 then ‘neova’

when instr(osuser, ‘alamo’) != 0 then ‘alamo’

when substr(osuser, 1,1)= ‘u’ then ‘uxxxx’

else ‘others’

end ), substr(machine, 1, 13)

order by 2;

select (case

when instr(osuser, ‘live’) != 0 then ‘liveops’

when instr(osuser, ‘neova’) != 0 then ‘neova’

when instr(osuser, ‘alamo’) != 0 then ‘alamo’

when substr(osuser, 1,1)= ‘u’ then ‘uxxxx’

else ‘others’

end ) OS_USER ,

substr(machine, 1, 13) MACHINE,

count(1) “TOTAL_SESSIONS”, count(distinct username) “TOTAL_UNIQ_USERS” ,

round(count(1)/count(distinct username),1) “Ratio”

from v$session

where substr(machine, 1, 10) != ‘FLOWERS_NT’

group by (case

when instr(osuser, ‘live’) != 0 then ‘liveops’

when instr(osuser, ‘neova’) != 0 then ‘neova’

when instr(osuser, ‘alamo’) != 0 then ‘alamo’

when substr(osuser, 1,1)= ‘u’ then ‘uxxxx’

else ‘others’

end ), substr(machine, 1, 13)

order by 2;

Oracle, SQL scripts

Post navigation

Previous Post: pvm_metric.sql for gathering report from vmstat tables
Next Post: temp_use.sql diplays usage of temp ts

Related Posts

  • Good RAC & Standby Notes Oracle
  • DBA_HIST_SQLSTAT contents Oracle
  • Jai Shree Ram Oracle
  • SYSOPER Mystery Oracle
  • tab.sql Oracle
  • oracle fast start failover best practice Oracle

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (393)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (0)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (342)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • Trace a SQL session from another session using ORADEBUG30-Sep-2025
  • SQL Server Vs Oracle Architecture difference25-Jul-2025
  • SQL Server: How to see historical transactions25-Jul-2025
  • SQL Server: How to see current transactions or requests25-Jul-2025
  • T-SQL Vs PL/SQL Syntax25-Jul-2025
  • Check SQL Server edition25-Jul-2025
  • Checking SQL Server Version25-Jul-2025
  • Oracle vs MYSQL Architecture differences (For DBAs)24-Jul-2025
  • V$INSTANCE of Oracle in MYSQL24-Jul-2025
  • Day to day MYSQL DBA operations (Compared with Oracle DBA)24-Jul-2025

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • How to find where datafile is created dbf_info.sql Oracle
  • UTL_FILE test program Oracle
  • kill all processes from specific user in solaris. Linux/Unix
  • Good notes for shared pool Oracle
  • move_arch_files.ksh Linux/Unix
  • Adding or Dropping Online Redo Log Files When Physical Standby in place Oracle
  • sesswait.sql Oracle
  • Kernel Parameters for Solaris Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme