set linesize 500
col owner format A20;
col segment_name format A40;
col segment_type format A20;
col tbs format A20;
col size_g format 999999999.9999;
WITH w1 AS
(SELECT ds.owner,
ds.segment_name,
ds.segment_type,
ds.tablespace_name,
ds.bytes
FROM dba_segments ds
WHERE ds.segment_type NOT IN ('LOBSEGMENT')
UNION ALL
SELECT ds.owner,
ds2.segment_name AS segment_name,
ds.segment_type,
ds.tablespace_name,
ds.bytes
FROM dba_segments ds, dba_lobs dl, dba_segments ds2
WHERE ds.owner = dl.owner
AND ds.segment_name = dl.segment_name
AND dl.owner = ds2.owner
AND dl.table_name = ds2.segment_name),
w2 AS
(SELECT w1.owner,
w1.segment_name,
w1.segment_type,
w1.tablespace_name as tbs,
SUM(w1.bytes) / 1024 / 1024 / 1024 AS size_g
FROM w1
GROUP BY w1.owner, w1.segment_name, w1.segment_type, w1.tablespace_name
ORDER BY 5 DESC)
SELECT * FROM w2 WHERE rownum < 11;