Oracle 测试常用表BIG_TABLE

发表于:2013-5-29 09:23

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:RobinsonCheng    来源:51Testing软件测试网采编

分享:

  二、基于Oracle 11g下的big_table

--==============================================
-- Create a test table for Oracle 11g
-- File   : cr_big_tb_11g.sql
-- Author : Robinson
-- Blog   : http://blog.csdn.net/robinson_0612
--==============================================

prompt
prompt     Create a big table from all_objects
prompt    ======================================
CREATE TABLE big_table
AS
SELECT ROWNUM id, a.*
FROM all_objects a
WHERE 1=0;
 
prompt
prompt  Modify table to nologgming mode
prompt  ==========================
ALTER TABLE big_table NOLOGGING;
 
prompt
prompt      Please input rows number to fill into big_table
prompt     ============================================
DECLARE
        l_cnt NUMBER;
        l_rows NUMBER := &1;
BEGIN
        INSERT /*+ append */
        INTO big_table
                SELECT rownum, a.*
                FROM all_objects a;
        l_cnt := SQL%ROWCOUNT;
        COMMIT;
        WHILE (l_cnt < l_rows)
        LOOP
                INSERT /*+ APPEND */
                INTO big_table
                        SELECT rownum + l_cnt
                             ,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
                        WHERE rownum <= l_rows - l_cnt;
                l_cnt := l_cnt + SQL%ROWCOUNT;
                COMMIT;
        END LOOP;
END;
/
 
prompt
prompt      Add primary key for  big table
prompt     =====================================
ALTER TABLE big_table ADD CONSTRAINT
big_table_pk PRIMARY KEY (id);
 
prompt
prompt      Gather statistics for big_table
prompt     =====================================
BEGIN
        dbms_stats.gather_table_stats(ownname => USER,
                                     tabname => 'BIG_TABLE',
                                     method_opt => 'for all indexed columns',
                                     cascade => TRUE);
END;
/
 
prompt
prompt      check total rows  for big_table
prompt     ====================================
SELECT COUNT(*)
FROM big_table;

  三、说明

  1、该校本根据Tom大师的原big_table整理而成。

  2、Oracle 11g all_objects 比Oracle 10g 多出两列,因此使用了2个不同的版本。

  3、big_table的id列为唯一值,并在之上创建了primary key。

  4、对于该表测试redo等相关信息是应启用logging模式。

22/2<12
重磅发布,2022软件测试行业现状调查报告~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计

法律顾问:上海漕溪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号