/*
 * Title  : fra_free.sql
 * Author : EXADIME LLC
 * Created: 19-Nov-2020
 * Updated: 11-Nov-2021
 * Release: 1.0.0
 * Purpose: Shows free space in flash recovery area.
 * History: N/A
 */

start oracle.ini

set echo off
set feedback off
set serverout on
set termout on

set linesize 125
set pagesize 0
set pause off
set long 80

set heading on
set headsep on
set underline on
set colsep " "

set define on
set verify off
set escape off
set embedded on

column dummy     noprint
column sno       format 9999            heading "#"
column name      format a40             heading "Name"
column total     format 99,999,999,999  heading "Total"
column used      format 99,999,999,999  heading "Used"
column free      format 99,999,999,999  heading "MB|Free"
column pct_used  format 999.99          heading "%|Used"

compute sum of total on report
compute sum of used  on report
compute sum of free  on report

break on report

accept p_order char prompt "Enter order by column {1|2|3|4|5|6} [asc|desc] " default 6

spool &&rpt_dir/fra_free.rpt

select
	row_number() over(order by &&p_order)               sno,
	name                                                name,
	space_limit/1024/1024                               total,
	space_used/1024/1024                                used,
	(space_limit-space_used)/1024/1024                  free,
	round(((space_used)/space_limit)*100,2)	            pct_used
from(
	select 
		name,
		space_limit,
		space_used
	from 
		v$recovery_file_dest
)
order by
	&&p_order
/

spool off

clear columns
clear computes

set embedded off
set escape off
set verify on
set define on

set colsep " "
set underline on
set headsep on
set heading on

set pause off
set pagesize 24
set linesize 80
set long 80

set termout on
set serverout off
set feedback on
set echo off