SET SERVEROUTPUT ON; DECLARE --Cursor Declaration CURSOR c1 IS SELECT SUM (ROUND ( (tablespace_usedsize * 8 * 1024) / 1024 / 1024, 2)) AS "used space", snap_id FROM DBA_HIST_TBSPC_SPACE_USAGE WHERE snap_id IN (SELECT snap_id FROM dba_hist_snapshot WHERE TO_CHAR (BEGIN_INTERVAL_TIME) BETWEEN '16/10/2011%18%' AND '20/10/2011%18') GROUP BY snap_id ORDER BY snap_id ASC; --Variable Declaretion row_counter NUMBER; db_used_size_1 NUMBER; db_used_size_2 NUMBER; snap_time TIMESTAMP; total_change NUMBER; BEGIN row_counter := 0; total_change := 0; db_used_size_2 := 0; db_used_size_1 := 0; FOR emp_rec IN c1 LOOP row_counter := row_counter + 1; IF MOD (row_counter, 2) = 0 THEN db_used_size_2 := emp_rec."used space"; ELSE db_used_size_1 := emp_rec."used space"; END IF; IF row_counter != 1 THEN EXECUTE IMMEDIATE 'select begin_interval_time from dba_hist_snapshot where snap_id =' || emp_rec.snap_id INTO snap_time; IF db_used_size_2 - db_used_size_1 != 0 AND db_used_size_1 != 0 AND db_used_size_2 != 0 THEN IF MOD (row_counter, 2) != 0 THEN DBMS_OUTPUT.put_line ( SUBSTR (TO_CHAR (snap_time), 1, INSTR (snap_time, ',') - 1) || ' -> ' || TO_CHAR (db_used_size_1 - db_used_size_2) || 'MB' || '--> %' || TO_CHAR ( ROUND ( 100 * (db_used_size_1 - db_used_size_2) / db_used_size_1, 2))); total_change := total_change + (db_used_size_1 - db_used_size_2); ELSE DBMS_OUTPUT.put_line ( SUBSTR (TO_CHAR (snap_time), 1, INSTR (snap_time, ',') - 1) || ' -> ' || TO_CHAR (db_used_size_2 - db_used_size_1) || 'MB' || '--> %' || TO_CHAR ( ROUND ( 100 * (db_used_size_2 - db_used_size_1) / db_used_size_1, 2))); total_change := total_change + (db_used_size_2 - db_used_size_1); END IF; END IF; END IF; END LOOP; DBMS_OUTPUT.put_line ('Total Change ' || TO_CHAR (total_change || ' MB')); END;