-- 创建eoda.big_table表
prompt
prompt 创建表eoda.big_table
declare 
    num number;
begin
    select count(1) into num from all_tables where table_name = upper ( 'big_table' ) and owner = upper( 'eoda' );
    if num = 1 then
        execute immediate 'drop table eoda.big_table';
    end if;

    execute immediate '
        create table eoda.big_table
        as 
        select 
            rownum ID,
            OWNER,
            OBJECT_NAME,
            SUBOBJECT_NAME,
            OBJECT_ID,
            DATA_OBJECT_ID,
            OBJECT_TYPE,
            CREATED,
            LAST_DDL_TIME,
            TIMESTAMP,
            STATUS,
            TEMPORARY,
            GENERATED,
            SECONDARY,
            NAMESPACE,
            EDITION_NAME
        from 
            all_objects
        where 
            1 = 0
    ';
end;
/
alter table big_table nologging;
declare
    l_cnt number;
    l_rows number := &numrows;
begin 
    insert /*+ append  */
    into big_table 
    select 
        rownum ID,  
        OWNER,
        OBJECT_NAME,
        SUBOBJECT_NAME,
        OBJECT_ID,
        DATA_OBJECT_ID,
        OBJECT_TYPE,
        CREATED,
        LAST_DDL_TIME,
        TIMESTAMP,
        STATUS,
        TEMPORARY,
        GENERATED,
        SECONDARY,
        NAMESPACE,
        EDITION_NAME
    from 
        all_objects
    where rownum <= &numrows;
    -- 
    l_cnt := sql%rowcount;
    commit;
    while (l_cnt < l_rows )
    loop
        insert /*+ append  */
        into big_table 
        select 
            rownum ID,  
            OWNER,
            OBJECT_NAME,
            SUBOBJECT_NAME,
            OBJECT_ID,
            DATA_OBJECT_ID,
            OBJECT_TYPE,
            CREATED,
            LAST_DDL_TIME,
            TIMESTAMP,
            STATUS,
            TEMPORARY,
            GENERATED,
            SECONDARY,
            NAMESPACE,
            EDITION_NAME
        from 
            big_table a
        where rownum <= l_rows - l_cnt;
        l_cnt := l_cnt +  sql%rowcount;
        commit;
    end loop;
end;
/

alter table big_table add constraint big_table_pk primary key(ID);

exec dbms_stats.gather_table_stats(user,'BIG_TABLE');
