Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • Load testing on Oracle 19C RAC with HammerDB Oracle
  • Consolidated Reference List Of Notes For Migration / Upgrade Service Requests -ID 762540.1 Oracle
  • Temporary tablespace explaination Oracle
  • V$INSTANCE of Oracle in MYSQL MYSQL
  • tuning commmand for cpu, ip and memory stats Linux/Unix
  • database trigger failing Oracle
  • Recovering lost SYS password Oracle
  • Follwoing korn shell is used to move files from source folder to destination folder and gzip it in destination folder. mv_iotto.ksh Linux/Unix
  • Set Role explaination. Oracle
  • oracle Dba site Oracle
  • When to rebuld B-tree index Oracle
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • Test Case for Inserting Multiple (2.3 Million rows in 26 Seconds) Oracle
  • pvm_pre_change.sql Oracle

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

  • oracle fast start failover best practice Oracle
  • Good link for LIO in Oracle ( Logical IOs) Oracle
  • ORA-8031 issue and solution if it is occuring due to truncate. Oracle
  • Find_stale_dr.sql finding stale physical DR.. Oracle
  • Find Stale DR Physical Standby Oracle
  • Oracle 11g RAC on OEL 5 and Vmware 2 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
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • MYSQL for Oracle DBA MYSQL
  • Oracle Material from OTN Oracle
  • First Entry in RAC Oracle
  • Gather Stats manually using DBMS_STATS after disabling DBMS_SCHEDULER jobs as previous entry Oracle
  • Day to day MYSQL DBA operations (Compared with Oracle DBA) MYSQL
  • oracle 11g RAC on vmware Oracle
  • oracle tips… from http://www.bijoos.com/oracle/douknow.htm Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme