Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a Total of Values IN() 1

Status
Not open for further replies.

tekdudedude

Technical User
Sep 29, 2007
79
0
0
Hello,

I am stuck. I have the following query that will produce a list of each Oracle tablespace and its total bytes for the schema entered:

Code:
set verify off
set linesize 140

ACCEPT SCHEMA PROMPT 'Enter schema name: '

SELECT tablespace_name, sum(bytes) Bytes
FROM dba_segments
WHERE tablespace_name IN('SI_DATA_&SCHEMA._TS','SI_INDEX_&SCHEMA._TS','TIDATA_&SCHEMA._TS','TIINDX_&SCHEMA._TS','TITEXTINDX_&SCHEMA._TS')
GROUP BY (tablespace_name);

The output looks like this:
Code:
TABLESPACE_NAME           BYTES
------------------------- ----------
SI_INDEX_SCOTT_TS            11993088
SI_DATA_SCOTT_TS              8978432
TIDATA_SCOTT_TS               2031616
TITEXTINDX_SCOTT_TS        1048838144
TIINDX_SCOTT_TS               1638400

How can I also get the total value (in bytes) of each entry of my IN clause?

The output I am looking for would be:
Code:
TABLESPACE_NAME           BYTES
------------------------- ----------
SI_INDEX_SCOTT_TS            11993088
SI_DATA_SCOTT_TS              8978432
TIDATA_SCOTT_TS               2031616
TITEXTINDX_SCOTT_TS        1048838144
TIINDX_SCOTT_TS               1638400

[b]TOTAL                      1073479680[/b]


Thanks,

TD
 
there is a better way to do it, but this should work
Code:
SELECT tablespace_name, sum(bytes) Bytes
FROM dba_segments
WHERE tablespace_name IN('SI_DATA_&SCHEMA._TS','SI_INDEX_&SCHEMA._TS','TIDATA_&SCHEMA._TS','TIINDX_&SCHEMA._TS','TITEXTINDX_&SCHEMA._TS')
GROUP BY (tablespace_name)
union all
select 'TOTAL', sum(bytes1) 
from (SELECT sum(bytes) bytes1
FROM dba_segments
WHERE tablespace_name IN('SI_DATA_&SCHEMA._TS','SI_INDEX_&SCHEMA._TS','TIDATA_&SCHEMA._TS','TIINDX_&SCHEMA._TS','TITEXTINDX_&SCHEMA._TS'));

that works for me
 
jaxtell,

YES! That was it. I always learn so much from you guys. :)

Thanks for posting,

TD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top