
prompt
prompt 'create table eoda.t'
declare row_count number;
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 eoda.big_table where 1=0
	';
end;
/

set autotrace traceonly statistics;
insert into eoda.t select * from eoda.big_table;
commit;
truncate table eoda.t;
insert /*+ APPEND */ into eoda.t select * from eoda.big_table;
commit;
set autotrace off;

-- variable  放在prompt里面会报错
variable redo number;
prompt
prompt 'logging'
declare row_count number;
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;
    :redo := get_stat_val('redo size');
	execute immediate '
		create table eoda.t
		as
		select * from all_objects
	';
	dbms_output.put_line( (get_stat_val('redo size') - :redo) || ' bytes of redo generated' );
end;
/

prompt
prompt 'nologging'
declare row_count number;
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;
    :redo := get_stat_val('redo size');
	execute immediate '
		create table eoda.t
		NOLOGGING
		as
		select * from all_objects
	';
	dbms_output.put_line( (get_stat_val('redo size') - :redo) || ' bytes of redo generated' );
end;
/
