Oracle 测试常用表BIG_TABLE

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

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

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

  创建测试用表,DBA经常用到,通常都是基于dba_objects来创建的比较多。本文根据Tom大师的big_table进行了整理,供大家参考。

  一、基于Oracle 10g下的big_table

--==============================================
-- Create a test table for Oracle 10g
-- File   : cr_big_tb_10g.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
                        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;

21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号