SELECT
T.TABLESPACE_NAME
,NVL(ROUND((SELECT SUM(BYTES)/1048576 FROM DBA_SEGMENTS@TESTE S WHERE S.TABLESPACE_NAME=T.TABLESPACE_NAME),2),0) MEGAS
FROM DBA_TABLESPACES@TESTE T
WHERE NOT EXISTS
(
SELECT 1 FROM DBA_TABLESPACES L
WHERE L.TABLESPACE_NAME=T.TABLESPACE_NAME
)
/
WITH LOCAL AS
(
SELECT TABLESPACE_NAME, NVL(ROUND(SUM(MAXBYTES)/1048576,2),0) MAXSIZE
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME
), REMOTO AS
(
SELECT S.TABLESPACE_NAME, NVL(ROUND(SUM(BYTES)/1048576,2),0) SEGS
FROM DBA_SEGMENTS@TESTE S
GROUP BY TABLESPACE_NAME
)
SELECT
L.*, R.SEGS
FROM LOCAL L
LEFT JOIN REMOTO R ON (L.TABLESPACE_NAME=R.TABLESPACE_NAME )
WHERE L.MAXSIZE < R.SEGS
/