如何恢复oracle db脚本,当使用分区时由标准版本可以使用



这是数据库使用关键字分区的示例脚本

create table ANDY.TEST
(
create_year    VARCHAR2(4) not null,    
no      VARCHAR2(10) not null,
id       VARCHAR2(10) not null,
update_id        VARCHAR2(10) not null,
update_date      DATE not null
)
partition by range (CREATE_YEAR)
(
partition TEST_2021 values less than ('2022')
tablespace TEST_DATA_01
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
),
partition TEST_2022 values less than ('2023')
tablespace TEST_DATA_02
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
minextents 1
maxextents unlimited
)
);
alter table ANDY.TEST
add constraint TEST_PK primary key (CREATE_YEAR, NO, ID)
using index 
local;
alter index ANDY.TEST_PK nologging;

问题来了,有没有办法让脚本改成标准版本可以使用?并有相同的结果

我只能运行create,其他脚本将无法运行

create table ANDY.TEST
(
create_year    VARCHAR2(4) not null,    
no      VARCHAR2(10) not null,
id       VARCHAR2(10) not null,
update_id        VARCHAR2(10) not null,
update_date      DATE not null
)

在同一个模式中不能有两个同名的表(实际上是任何对象)。所以这取决于你想要达到什么目标。

明显的选择是在运行备用脚本之前删除一个表。

另一种方法是以不同的方式命名表。但是,您可能希望对这两种变体运行相同的代码。这就是同义词发挥作用的地方。

第一个脚本:

create table ANDY.TEST_PARTITIONED ...

第二个脚本:

create table ANDY.TEST_STANDARD ...

要允许代码引用分区表,请使用这个同义词:

create or replace synonym andy.test for andy.test_partitioned;

要允许代码引用未分区表,请使用这个同义词:

create or replace synonym andy.test for andy.test_standard;

如果这个答案没有解决你的问题,请编辑你的问题

提供有关您想要实现的目标的更多细节。

最新更新