How to include more than one partition in a single select statement in oracle

半腔热情 提交于 2019-12-08 06:47:59

问题


create table agg_summary (period date, lvl_id number);

Partition has been created for lvl_id which includes 1,2,3 as a separate partition for each id.

How to access agg_summary to have 1 and 2 together?


回答1:


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% 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.



来源:https://stackoverflow.com/questions/24027848/how-to-include-more-than-one-partition-in-a-single-select-statement-in-oracle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!