Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Set Role explaination. Oracle
  • ORACLE_SID in sqlplus Oracle
  • Create type and Grant on it. Oracle
  • oracle 11g RAC on vmware Oracle
  • MYSQL and Oracle Comparison for Oracle DBA MYSQL
  • My Test Case On 21-OCT-2005 Oracle
  • 10g oem configuration Oracle
  • Distributed Transaction Troubleshooting. Oracle
  • OPENING A STANDBY DATABASE IN READ-ONLY MODE Oracle
  • checking connectivity between two servers Linux/Unix
  • Process Map for CPU and Memory for OS processes Linux/Unix
  • Read CSV File using Python Python/PySpark
  • adding new line after specific pattern using sed Linux/Unix
  • Ports used by Oracle Software Oracle
  • Finding last recovered file on DR and remove all chanracters before any “/” 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

  • ORA-00064: object is too large to allocate on this O/S during startup Oracle
  • Implementing Listener Security Oracle
  • ORA-1841 Error Connecting to Upgraded Database After Set PASSWORD_LIFE_TIME Oracle
  • How to find pinned objects from shared pool. (pinned via dbms_shared_pool.keep) Oracle
  • Drop database in Oracle 10g Oracle
  • GSQ.sql 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
  • ORA-01220 Oracle
  • To see mem usage and CPU usage system wide. Linux/Unix
  • Locally Managed Tablespace and Dictionary managed tablespace (LMT-DMT) Oracle
  • Finding Oracle Patches with opatch Oracle
  • How to find the real execution plan and binds used in that explain plan in Oracle 10g?? Oracle
  • Global Unique Identifier Generation in Oracle 9.2 SYS_GUID() Oracle
  • cur_sql.sql Oracle
  • find checksum of a file. Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme