Ora 11g 中的数据库分区

发布于 2024-10-21 03:14:14 字数 64 浏览 5 评论 0原文

我需要从系统参数中选择需要创建分区的日期,然后需要使用存储过程创建分区。任何指导。 使用的是Oracle 11g。

I need to select a date from system param for which the partition needs to be created and then need to create the partition using a stored Procedure. ANy guidance.
Oracle 11g is being used.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生来就爱笑 2024-10-28 03:14:14

Ronan,

也许你可以采用区间划分?您使用的是 11g,因此可以使用间隔分区。当插入数据并且所需的分区尚不可用时,这会在所需的基础上生成分区。

Ronan,

maybe you can adopt interval partitioning? You are using 11g so interval partitioning is available to you. This generates partitions on an is needed base, when the data is inserted and the partition that is needed is not yet available.

岁月静好 2024-10-28 03:14:14

您可以使用动态 PL/SQL,例如:

select the_date into l_date from system_parameters where...;

execute immediate 'alter table mytable add partition p_' || replace(l_date,'-','')
|| ' values less than (to_date(''' || l_date || ''',''DD-MON-YYYY'')';

You could use dynamic PL/SQL something like:

select the_date into l_date from system_parameters where...;

execute immediate 'alter table mytable add partition p_' || replace(l_date,'-','')
|| ' values less than (to_date(''' || l_date || ''',''DD-MON-YYYY'')';
暮年慕年 2024-10-28 03:14:14

我同意@ik_zelf 的答案,如果您要在日期上实现分区,并且想要在日期到来时进行分区,请进行间隔分区。也不需要存储过程。

这是Oracle 11g 中的一个新特性。当插入记录时,它会为特定间隔创建分区,因此您不必担心新分区。新的分区将被赋予一个系统名称,如 SYS_PXXX。

这就是间隔分区的方式。

CREATE TABLE interval_tab (
  id           NUMBER,
  code         VARCHAR2(10),
  description  VARCHAR2(50),
  created_date DATE
)
PARTITION BY RANGE (created_date)
INTERVAL(NUMTOYMINTERVAL(1,'MONTH')) -- change to 12 for an year  
(
   PARTITION part_01 values LESS THAN (TO_DATE('01-JAN-2012','DD-MON-YYYY'))
);

间隔分区与早期的分区无关,间隔之前创建的最后一个分区将是这里的过渡点。

您也可以使用

ALTER TABLE 方式来添加分区。

I agree with the answer from @ik_zelf, if you are going to implement a partiotion over date, and want to make as and when the date comes, Go for interval Partioning. There would be no need for a Stored Procedure as well.

Its a new feature in the Oracle 11g. Which Creates partiotioning for particular intervals when the records are inserted, so you need not worry on the new partitions. The new Partiotions would be given a system name as well like SYS_PXXX..

This is how go for Interval Partition..

CREATE TABLE interval_tab (
  id           NUMBER,
  code         VARCHAR2(10),
  description  VARCHAR2(50),
  created_date DATE
)
PARTITION BY RANGE (created_date)
INTERVAL(NUMTOYMINTERVAL(1,'MONTH')) -- change to 12 for an year  
(
   PARTITION part_01 values LESS THAN (TO_DATE('01-JAN-2012','DD-MON-YYYY'))
);

Interval Partition has nothing to do with the earlier Partition, the last partition created before interval would be the transition point here.

You can also go with the

ALTER TABLE way to ADD PARTITION as well..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文