
prompt
prompt 创建数据库表eoda.t
declare 
    num number;
begin
    select count(1) into num from user_tables where table_name = upper( 't' );
    if num = 1 then
        execute immediate 'drop table eoda.t';
    end if;
    execute immediate '
        create table eoda.t as select * from all_objects
    ';
    dbms_stats.gather_table_stats( user, 'T' );
end;
/

/** 
 * 方法1要比方法二快，具体执行要看电脑性能和oracle配置.
 **/
prompt
prompt update表eoda.t
variable n number
begin
    dbms_output.put_line ( 'method one' );
    :n := dbms_utility.get_cpu_time;
    update eoda.t set object_name = lower(object_name);
    commit;
    dbms_output.put_line ( (dbms_utility.get_cpu_time - :n) || ' cpu hsesc...');
    dbms_output.put_line ( 'method two' );
    :n := dbms_utility.get_cpu_time;
    for x in ( select rowid rid,object_name,rownum r from eoda.t )
    loop 
        update eoda.t set object_name = lower(object_name) where rowid = x.rid;
        if ( mod( x.r,100 ) = 0 ) then 
            commit;
        end if;
    end loop;
    commit;
    dbms_output.put_line ( (dbms_utility.get_cpu_time - :n) || ' cpu hsesc...');
    /** // 下面部分代码报错，具体原因未知
    dbms_output.put_line ( 'method three' );
    :n := dbms_utility.get_cpu_time;
    declare 
        type  ridArray is table of rowid;
        type  vcArray is table of eoda.t.object_name%type;
        
        l_rids   ridArray;
        l_names  vcArray;
        cursor c is select rowid,object_name,rownum from eoda.t;
        begin
            open c;
            loop
                fetch c bulk collect into l_rids,l_names limit 100;
                forall i in l_rids.count
                    update eoda.t 
                       set object_name = lower( l_names(i) ) 
                     where rowid = l_rids(i);
                commit;
                exit when c%notfound;
            end loop;
            close c;
        end;
    dbms_output.put_line ( (dbms_utility.get_cpu_time - :n) || ' cpu hsesc...');
    **/
end;
/

