**********************************************
* Description: SQL for Querying Database Size
* Compatiablity: RDBMS 10g, 11g, 12c
* Date: 17:56 PM EST, 01/09/2017
**********************************************


<1> Introduction:
     |
     |
     |__ o. USEDGB   = Total size of [ Data_File + Log_File + Temp_File occupied on disk storage ] 
     |   o. FREEGB   = Total size of [ Free extend within all tablespaces ] 
     |   o. DBSIZEGB = USEDGB - FREEGB
     |
     |
     |__ SQL> select round(sum(used.bytes) / 1024 / 1024 /1024 ) usedGB, 
              round(temp.temp_used /1024 / 1024 / 1024) tempUsed, 
              round(free.p / 1024 / 1024 / 1024) freeGB, 
              (round(sum(used.bytes) / 1024 / 1024 /1024 ))-(round(free.p / 1024 / 1024 / 1024)) dbSizeGB
              from (select bytes from dba_data_files
              union all
              select bytes from dba_temp_files
              union all
              select bytes from v$log) used, 
              (select sum(bytes) as p from dba_free_space) free,
              (select nvl(sum(bytes),0) as temp_used from dba_temp_files) temp
              group by free.p, temp.temp_used;
         
         	 
         		USEDGB   TEMPUSED     FREEGB   DBSIZEGB
         		------- ---------- ---------- ----------
         		    88         20         20         68

	
	

Your Comments