【问题标题】:insert data from current month of partitioned table to a non partitioned table in oracle将分区表当前月份的数据插入到oracle中的非分区表中
【发布时间】:2014-02-26 17:10:54
【问题描述】:

我有一个名为 backup_audit 的分区备份表。我需要将当前月份的分区数据插入另一个名为 audit 的非分区表中,该表没有数据。我们如何创建一个sql查询来获取当前月份的分区并加载到未分区的表中?

这是我尝试过的(没有成功):

select partition_name
from dba_tab_partition
where partition_name in (
    select high_value
    from dba_tab_partition
    where table_name='table_backup' and high_value in (
        select to_char(sysdate, 'YYYYMM') from dual
    )
)

【问题讨论】:

  • 我试过了,但没有成功
  • select partition_name from dba_tab_partition where partition_name in (select high_value from dba_tab_partition where table_name='table_backup' and high_value in (select to_char(sysdate, 'YYYYMM') from dual)
  • “high_value”是 LONG 数据类型(不幸的是)。您需要使用 pl/sql 来提取要比较的时间戳(我知道 pita)

标签: sql oracle


【解决方案1】:

您不需要参考分区来选择当前月份的数据。假设您的 backup_audit 表由audit_date 进行范围分区:

insert 
  into audit(col1, col2, col3, ColN)
select col1, col2, col3, ColN
  from backup_audit
 where audit_date >= trunc(sysdate, 'MM')
   and audit_date < last_day(trunc(sysdate)) + 1;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-10
    • 1970-01-01
    • 2018-07-11
    • 2021-12-25
    • 2012-02-12
    相关资源
    最近更新 更多