11g环境
1. 创建实验表和实验数据
----------
SQL> create table test_p (id number);
Table created.
SQL> declare
i number:=1;
begin
for i in 1..3000 loop
insert into scott.test_p values(i);
commit;
end loop;
end;
/
PL/SQL procedure successfully completed.
----------
SQL> create table test_p2
partition by range (id)
(
partition p1 values less than (1000),
partition p2 values less than (2000),
partition p3 values less than (3000),
partition p4 values less than (maxvalue)
)
as
select * from test_p;
Table created.
----------
SQL> create index t_p on test_p(id);
Index created.
3.2 检查实验表是否可以在线重定义
----------
SQL> exec dbms_redefinition.can_redef_table( scott,test_p,dbms_redefinition.cons_use_pk);
BEGIN dbms_redefinition.can_redef_table( scott,test_p,dbms_redefinition.cons_use_pk); END;
*
ERROR at line 1:
ORA-12089: cannot online redefine table "SCOTT"."TEST_P" with no primary key
ORA-06512: at "SYS.DBMS_REDEFINITION", line 143
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1635
ORA-06512: at line 1
----------
SQL> alter table test_p add constraint pt_p primary key(id);
Table altered.
SQL> exec dbms_redefinition.can_redef_table( scott,test_p,dbms_redefinition.cons_use_pk);
PL/SQL procedure successfully completed.
----------
SQL> create table p_temp (id number)
partition by range (id)
(
partition p1 values less than(1000),
partition p2 values less than(2000),
partition p3 values less than(3000),
partition p4 values less than(maxvalue)
);
Table created.
SQL> alter table p_temp add constraint pp_temp primary key(id);
Table altered.
----------
SQL> exec dbms_redefinition.start_redef_table(scott, test_p, p_temp);
PL/SQL procedure successfully completed.
----------
SQL> exec dbms_redefinition.finish_redef_table(scott, test_p, p_temp);
PL/SQL procedure successfully completed.
SQL> select table_name,partition_name from user_tab_partitions where table_name=TEST_P;
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
TEST_P P1
TEST_P P2
TEST_P P3
TEST_P P4
12c环境下
----------
SQL> create table test_p (id number);
Table created.
SQL> declare
i number:=1;
begin
for i in 1..3000 loop
insert into scott.test_p values(i);
commit;
end loop;
end;
/
PL/SQL procedure successfully completed.
----------
SQL> select table_name,partition_name from user_tab_partitions where table_name=TEST_P;
no rows selected
----------
SQL> alter table test_p add constraint tp_p primary key (id);
Table altered.
----------
SQL> alter table test_p modify
partition by range (id)
(
partition p1 values less than (1000),
partition p2 values less than (2000),
partition p3 values less than (3000),
partition p4 values less than (maxvalue)
)
update indexes (tp_p global);
Table altered.
----------
SQL> select table_name,partition_name from user_tab_partitions where table_name=TEST_P;
TABLE_NAME PARTITION_NAME
------------------------------
TEST_P P1
TEST_P P2
TEST_P P3
TEST_P P4
对分区表进行扩展的两种情况
----------
SQL> create table test_p2 (id number)
partition by range (id)
(
partition p1 values less than (1000),
partition p2 values less than (2000),
partition p3 values less than (3000)
);
Table created.
----------
SQL> select table_name,partition_name from user_tab_partitions where table_name=TEST_P2;
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
TEST_P2 P1
TEST_P2 P2
TEST_P2 P3
----------
SQL> alter table test_p2 add partition p4 values less than (4000);
Table altered.
----------
SQL> select table_name,partition_name from user_tab_partitions where table_name=TEST_P2;
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
TEST_P2 P1
TEST_P2 P2
TEST_P2 P3
TEST_P2 P4
----------
SQL> alter table test_p add partition p5 values less than (4000);
alter table test_p add partition p5 values less than (4000)
*
ERROR at line 1:
ORA-14074: partition bound must collate higher than that of the last partition
此时,可以通过分割存在maxvalue的分区来实现对分区的增加:
----------
SQL> alter table test_p split partition p4 at (4000) into (partition p5,partition p4);
Table altered.
Dblink的创建
SQL> conn scott/oracle
Connected.
SQL> select * from user_sys_privs;
USERNAME PRIVILEGE ADM
------------------------------ ---------------------------------------- ---
SCOTT UNLIMITED TABLESPACE NO
赋予当前用户创建dblink的权限:
----------
SQL> grant create public database link to scott;
Grant succeeded.
SQL> grant create database link to scott;
Grant succeeded.
----------
SQL> select * from user_sys_privs;
USERNAME PRIVILEGE ADM
------------------------------ ---------------------------------------- ---
SCOTT CREATE DATABASE LINK NO
SCOTT UNLIMITED TABLESPACE NO
SCOTT CREATE PUBLIC DATABASE LINK NO
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129605.html
摘要:新晋技术专家下面是墨天轮部分新晋的技术专家。大家可以点击往期阅读墨天轮技术专家邀请函了解详情,申请成为我们的技术专家,加入专家团队,与我们一起创建一个开放互助的数据库技术社区。新关联公众号墨天轮是一个开放互助的数据库技术社区。 引言 近期我们在DBASK小程序增加了数据库 MongoDB、Redis、 Elasticsearch、DB2、Weblogic 等新的的专题栏目和一些新的技术...
阅读 1235·2023-01-11 13:20
阅读 1543·2023-01-11 13:20
阅读 996·2023-01-11 13:20
阅读 1651·2023-01-11 13:20
阅读 3958·2023-01-11 13:20
阅读 2456·2023-01-11 13:20
阅读 1290·2023-01-11 13:20
阅读 3452·2023-01-11 13:20