且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在oracle的单个select语句中包含多个分区

更新时间:2023-01-19 23:39:14

至少有三种方法可以从特定分区中选择数据.请参阅手册以获取对语法.

There are at least three ways to select data from specific partitions. See the manual for a thorough description of the syntax.

create table agg_summary (period date, lvl_id number)
partition by list (lvl_id)
(
    partition p1 values (1),
    partition p2 values (2),
    partition p3 values (3)
);

--#1: Normal predicate:
select * from agg_summary where lvl_id in (1,2);

--#2: Partition_extended_name:
select * from agg_summary partition (p1)
union all
select * from agg_summary partition (p2);

--#3: Partition_excension_clause:
select * from agg_summary partition for (1)
union all
select * from agg_summary partition for (2);

99.9% 的时间选项 #1 应该足够了.Oracle 将自动确定使用哪些分区并正确修剪.对于修剪无法正常工作的情况,或者根据分区名称或键进行选择更合乎逻辑,选项 #2 或 #3 应该有效.

99.9% of the time option #1 should be sufficient. Oracle will automatically determine which partitions are used and will prune correctly. For cases where pruning doesn't work correctly, or it's more logical to select based on the partition name or key, options #2 or #3 should work.