/*
 * 反向键索引
 *
 */

select 90101, dump(90101,16) from dual
 union all
select 90102, dump(90102,16) from dual
 union all
select 90103, dump(90103,16) from dual
/

prompt
prompt 创建表空间assm
declare
	row_count number(5);
begin
	select count(1) into row_count from dba_tablespaces where tablespace_name = upper('assm');
	if row_count = 0 then
		execute immediate '
			create tablespace assm
			datafile ''/u01/app/oracle/oradata/xe/assm.dbf'' size 1m autoextend on next 1m
			segment space management auto
		';
	end if;
end;
/

prompt
prompt 创建表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 tablespace assm
		as
		select 0 id,owner, object_name,subject_name,
		  object_id,data_object_id,object_type,created,
		last_ddl_time,timestamp,status,temporary,
		generated,secondary
		 from all_obejects a
		where 1=0
	';
	alter table eoda.t add constraint t_pk on eoda.t(id) primary key (id)
	using index (create index t_pk on eoda.t(t) &indexType tablespace assm );
end;
/

prompt
prompt 创建存储过程eoda.do_sql
create or replace procedure do_sql
as
begin
	for x in (
			select rownum r,OWNER,OBJECT_NAME,SUBJECT_NAME,
			  OBJECT_ID,DATA_OBJECT_TYPE,CREATED,
	    	  LAST_DDL_TIME,TIMESTAMP,STATUS,TEMPORARY,
	    	  GENERATED,SECONDARY
		)
	loop
		insert into eoda.t
		(
			id,owner,object_name,subject_name,
			object_id,data_object_id,object_type,created,
			last_ddl_time,timestamp,status,temporary,
			generated, secondary
		)
		values
		(
			s.nextval,x.owner,x.object_name,x.subject_name,
			x.object_id,x.data_object_id,x.object_type,x.created,
			x.last_ddl_time,x.timestamp,x.status,x.temporary,
			x.generated, x.secondary
		);
		if ( mod(x.r,100) = 0 ) then
			commit;
		end if;
	end loop;
	commit;
end;
/

prompt
prompt 模拟加载转换加载..
begin
	declare c cursor for select * from all_objects;
	open c;
	whenever notfound do break;
	for (;;)
	{
		fetch c into :owner:owner_i,
		:object_name:object_name_i, :subject_name:subject_name_i,
		:object_id:object_id_i, :data_object_id:data_object_id_i,
		:object_type:object_type_i, :created:created_i,
		:last_ddl_time:last_ddl_time_i, :timestamp:timestamp_i,
		:status:status_i, :temporary:temporary_i,
		:generated:generated_i, :secondary:secondary_i;

		insert into eoda.t
		(
			id,owner,object_name,subject_name,
			object_id,data_object_id,object_type,created,
			last_ddl_time,timestamp,status,temporary,
			generated, secondary
		)
		values
		(
			s.nextval_i,x.owner_i,x.object_name_i,x.subject_name_i,
			x.object_id_i,x.data_object_id_i,x.object_type_i,x.created_i,
			x.last_ddl_time_i,x.timestamp_i,x.status_i,x.temporary_i,
			x.generated_i, x.secondary_i
		);

		if ( (++cnt%100) == 0  )
		{
			commit;
		}
	}
	whenever notfound continue;
	commit;
	close c;
end;
/
