
prompt
prompt 'create function eoda.get_stat_val'
create or replace function eoda.get_stat_val (p_name in varchar2 ) return number
as
	l_val    number;
begin
	select b.value
	  into l_val
	  from v$statname a,v$mystat b
	 where a.statistic# = b.statistic#
	   and a.name = p_name;
	return l_val;
end;
/

prompt
prompt 'create table eoda.t'
declare row_count number(5);
begin
	select count(1) into row_count from user_tables where table_name = upper('t');
	if row_count = 1 then
		execute immediate 'drop table eoda.t';
	end if;
	execute immediate '
		create table eoda.t
		as
		select *
		  from big_table
		 where 1 = 0
	';
end;
/

prompt
prompt 'test commit'
declare
	l_redo  number;
	l_cpu   number;
	l_ela   number;
begin
	dbms_output.put_line ( '-' || '      Rows' || '        Redo' || '     CPU' || ' Elapsed'  );
	for i in 1 .. 6
	loop
		l_redo := get_stat_val ( 'redo size' );
		insert into eoda.t select * from big_table where rownum <= power(10,i);
		l_cpu := dbms_utility.get_cpu_time;
		l_ela := dbms_utility.get_time;
		commit work write wait;
		dbms_output.put_line( '-' ||
			to_char( power(10,i),'9,999,999' )  ||
			to_char( (get_stat_val('redo size') - l_redo ), '999,999,999' ) ||
			to_char( (dbms_utility.get_cpu_time - l_cpu),'999,999' ) ||
			to_char( (dbms_utility.get_time - l_ela),'999,999' ));
	end loop;
end;
/

prompt
prompt 'test rollback'
declare
	l_redo  number;
	l_cpu   number;
	l_ela   number;
begin
	dbms_output.put_line ( '-' || '      Rows' || '        Redo' || '     CPU' || ' Elapsed'  );
	for i in 1 .. 6
	loop
		l_redo := get_stat_val ( 'redo size' );
		insert into eoda.t select * from big_table where rownum <= power(10,i);
		l_cpu := dbms_utility.get_cpu_time;
		l_ela := dbms_utility.get_time;
		-- commit work write wait;
		rollback;
		dbms_output.put_line( '-' ||
			to_char( power(10,i),'9,999,999' )  ||
			to_char( (get_stat_val('redo size') - l_redo ), '999,999,999' ) ||
			to_char( (dbms_utility.get_cpu_time - l_cpu),'999,999' ) ||
			to_char( (dbms_utility.get_time - l_ela),'999,999' ));
	end loop;
end;
/
