如何从oracle表的多个分区中选择数据

时间:2018-09-24 07:28:46

标签: sql oracle

我正在尝试从分区表中的多个分区中选择数据。它适用于单个分区(select * from table partition(ParititonName),但不能选择多个分区(select * from table partitions(Part1,part2)。 您能否让我知道如何在单个查询中选择多个分区。

2 个答案:

答案 0 :(得分:3)

您不必担心。 “分区”与“存储”有关,Oracle会注意这一点。您所需要做的就是运行所需的任何查询,例如如果EMP表在DEPTNO列上进行了分区(每个部门都进入了自己的分区),您仍然可以运行

select deptno, empno, ename, sal
from emp
where deptno in (10, 20);

您未指定分区。

答案 1 :(得分:1)

如果您需要在查询中明确解决分区名称-这不是典型的用例(因为您经常使用WHERE谓词进行分区修剪)-但对于{ {1}},您可以使用hash partitioning访问更多分区。

UNION ALL

execution plan显示(请参阅列Pstart和Pstop)仅访问分区1和2。

select * from TAB partition (Part1) 
union all
select * from TAB partition (Part2);