×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Getting a Total of Values IN()

Getting a Total of Values IN()

Getting a Total of Values IN()

(OP)
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

TOTAL                      1073479680


Thanks,

TD

RE: Getting a Total of Values IN()

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

RE: Getting a Total of Values IN()

(OP)
jaxtell,

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

Thanks for posting,

TD

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close