我有一个带有分区的备份表,称为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
)
)
答案 0 :(得分: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;