你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle 测试常用表BIG_TABLE

[日期:2013-03-02] 来源:robinson  作者:robinson [字体:大 中 小]

二、基于Oracle 11g下的big_table

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模式。

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
相关资讯       Oracle测试常用表 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款