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

Mah*_*eta 2 sql oracle

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

Mar*_*ber 5

如果您需要在查询中明确寻址分区名称 - 这不是典型用例(因为您经常使用 WHERE 谓词进行分区修剪) - 但可能是 的情况hash partitioning,您可以用来UNION ALL访问更多分区。

select * from TAB partition (Part1) 
union all
select * from TAB partition (Part2);
Run Code Online (Sandbox Code Playgroud)

执行计划显示(请参阅 Pstart 和 Pstop 列)仅访问分区 1 和 2。

----------------------------------------------------------------------------------------------------
| Id  | Operation                   | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
----------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |      |     2 |    86 |     4   (0)| 00:00:01 |       |       |
|   1 |  UNION-ALL                  |      |       |       |            |          |       |       |
|   2 |   PARTITION HASH SINGLE     |      |     1 |    43 |     2   (0)| 00:00:01 |     1 |     1 |
|   3 |    TABLE ACCESS STORAGE FULL| TAB  |     1 |    43 |     2   (0)| 00:00:01 |     1 |     1 |
|   4 |   PARTITION HASH SINGLE     |      |     1 |    43 |     2   (0)| 00:00:01 |     2 |     2 |
|   5 |    TABLE ACCESS STORAGE FULL| TAB  |     1 |    43 |     2   (0)| 00:00:01 |     2 |     2 |
----------------------------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)