RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1292952
Accepted
Анатолий Эрнст
Анатолий Эрнст
Asked:2022-06-08 12:17:20 +0000 UTC2022-06-08 12:17:20 +0000 UTC 2022-06-08 12:17:20 +0000 UTC

如何将分区表转换为常规表?

  • 772

出于实验的目的,通过alter table modify ...使用间隔分区和静态子分区将普通表执行到分区表中。

有没有办法让它恢复到反向状态?

我只是不想恢复 DDL 和复制数据(这需要很长时间并且需要资源)。

sql
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    0xdb
    2022-06-10T00:26:05Z2022-06-10T00:26:05Z

    ALTER TABLE命令没有modify_to_partitioned子句的反向类似物。

    一种可能的替代方法是使用PARTITION_OPTIONS=merge选项导出/导入。

    表格示例:

    create table t1 (id int primary key, memo varchar2(16), created date)
    partition by range (created) (
        partition t1_part_2020 values less than (date'2021-01-01'),
        partition t1_part_2021 values less than (maxvalue))
    /
    insert into t1 
        select rownum, 'memo row '||rownum, date'2020-01-01'+(rownum-1)
        from dual connect by level<=999
    /    
    commit;
    
    select table_name, partitioned 
    from user_tables where table_name='T1'
    /
    TABLE_NAME PARTITIONED 
    ---------- ------------
    T1         YES         
    

    出口也不例外。接下来,应该删除表(不要忘记备份!!!):

    $ expdp me/me@dbsrv/pdb1 directory=data_pump_dir tables=t1 dumpfile=t1.dmp logfile=exp.log
    [...]
    . . exported "ME"."T1":"T1_PART_2020"                    16.05 KB     366 rows
    . . exported "ME"."T1":"T1_PART_2021"                    23.81 KB     633 rows
    Master table "ME"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
    ******************************************************************************
    
    SQL> drop table t1 cascade constraints purge;
    

    使用合并分区的选项导入:

    $ impdp me/me@dbsrv/pdb1 directory=data_pump_dir partition_options=merge \
      dumpfile=t1.dmp logfile=imp.log
    
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    . . imported "ME"."T1":"T1_PART_2021"                    23.81 KB     633 rows
    . . imported "ME"."T1":"T1_PART_2020"                    16.05 KB     366 rows
    
    select table_name, partitioned 
    from user_tables where table_name='T1'
    /
    TABLE_NAME PARTITIONED 
    ---------- ------------
    T1         NO          
    
    • 5
  2. 0xdb
    2022-06-11T19:25:47Z2022-06-11T19:25:47Z

    另一种解决方案是使用 DBMS_REDEFINITION 包在线重组表,这会将其停机时间减少到几分钟。

    为此,检查重组表的可能性,并使用目标表的结构创建内部表,在我们的例子中没有分区:

    exec sys.dbms_redefinition.can_redef_table (uname => 'db', tname => 't1')
    
    create table intert1 (id int primary key, memo varchar2(16), created date)
    /
    

    接下来的步骤包括:运行重组、复制所有依赖项、错误检查和可选的同步表:

    begin
        dbms_redefinition.start_redef_table (
        uname => 'me', 
        orig_table   => 't1',
        int_table    => 'intert1');
    end;
    /
    declare
        numerr pls_integer;
    begin
        dbms_redefinition.copy_table_dependents (
            uname            => 'me', 
            orig_table       => 't1',
            int_table        => 'intert1',
            copy_indexes     => dbms_redefinition.cons_orig_params, 
            copy_triggers    => true, 
            copy_constraints => true, 
            copy_privileges  => true, 
            ignore_errors    => true, 
            num_errors       => numerr);
        dbms_output.put_line ('errors='||numerr); 
    end;
    /
    select object_name, base_table_name, ddl_txt 
    from dba_redefinition_errors;
    
    exec dbms_redefinition.sync_interim_table ( -
        uname => 'me', orig_table => 't1', int_table => 'intert1');
    

    重组完成后,目标表将被锁定几分钟。然后,完全匹配内部表的结构,后者可以删除:

    exec dbms_redefinition.finish_redef_table ( -
        uname => 'me', orig_table => 't1', int_table => 'intert1');
    
    select table_name, partitioned 
    from user_tables where table_name='T1';
    
    TABLE_NAME PARTITIONED 
    ---------- ------------
    T1         NO          
    
    drop table intert1 purge;
    
    • 4

相关问题

  • 通过 OUT 参数从过程结果输出

  • ON 关键字附近的语法错误 - SQL

  • 多表查询中的 Count() 聚合函数

  • 根据时间更改单元格中的日期

  • phpMyAdmin 中的错误 #1064 SQL 查询

  • Qt:包含变量的数据库查询

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5