【问题标题】:How to include more than one partition in a single select statement in oracleoracle如何在一个select语句中包含多个分区
【发布时间】:2022-04-11 21:51:52
【问题描述】:
create table agg_summary (period date, lvl_id number);

已为 lvl_id 创建分区,其中包括 1,2,3 作为每个 id 的单独分区。

如何访问agg_summary将1和2放在一起?

【问题讨论】:

  • 你有没有试过查询lvl_id在(1, 2)的位置?虽然跨分区可能效果不佳,但它应该可以工作。
  • 样本数据和期望的结果会有所帮助。
  • 答案取决于您打算执行的查询,并且取决于您的可用性要求。我本质上是指您如何索引表。有很多选择。

标签: oracle partition


【解决方案1】:

至少有三种方法可以从特定分区中选择数据。有关语法的详细说明,请参阅 the manual

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 应该可以工作。

【讨论】:

    【解决方案2】:

    当使用哈希作为分区选项时,您可以考虑将“ora_hash()”函数作为您的 qry 的 WHERE 条件的标准。

    因此,如果使用 CUSTOMER_ID 对表 CUSTOMERS 进行哈希处理,则 32 个分区的分区键和所需的分区是第 1、第 2 和第 3,那么您的 WHERE 条件应如下所示:

    select * from CUSTOMERS C where MOD(ORA_HASH(CUSTOMER_ID),32) in (1,2,3);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-21
      • 2016-03-18
      • 2016-01-18
      • 1970-01-01
      • 2018-09-17
      • 1970-01-01
      相关资源
      最近更新 更多