您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“Oracle12.2怎么將分區(qū)移動到不同的表空間中”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“Oracle12.2怎么將分區(qū)移動到不同的表空間中”吧!
下面的例子將演示如何聯(lián)機(jī)重定義多個分區(qū)并將基于范圍分區(qū)的表salestable的兩個分區(qū)移動到新表空間中。原始表jy.salestable的創(chuàng)建如下:
SQL> create table jy.salestable 2 (s_productid number, 3 s_saledate date, 4 s_custid number, 5 s_totalprice number) 6 tablespace users 7 partition by range(s_saledate) 8 (partition sal10q1 values less than (to_date('01-apr-2010', 'dd-mon-yyyy')), 9 partition sal10q2 values less than (to_date('01-jul-2010', 'dd-mon-yyyy')), 10 partition sal10q3 values less than (to_date('01-oct-2010', 'dd-mon-yyyy')), 11 partition sal10q4 values less than (to_date('01-jan-2011', 'dd-mon-yyyy'))); Table created.
這個例子會將分區(qū)sal10q1與sal10q2移動到example表空間中。sal10q3與sal10q4分區(qū)不會被移動。為了移動分區(qū)表空間example必須存在。這里已經(jīng)先創(chuàng)建好了表空間example。對原始表jy.salestable創(chuàng)建一個本地分區(qū)索引,操作如下:
SQL> create index jy.sales_index on jy.salestable (s_saledate, s_productid, s_custid) local; Index created.
注意,在12.2中也可以執(zhí)行alter table ... move partition ... online語句來將分區(qū)移動到其它表空間中。
聯(lián)機(jī)重定義操作如下:
1.用要執(zhí)行聯(lián)機(jī)重定義操作的用戶登錄數(shù)據(jù)庫
SQL> conn jy/jy@jypdb Connected.
2.驗證原始表jy.salestable是否可以執(zhí)行聯(lián)機(jī)重定義
SQL> begin 2 dbms_redefinition.can_redef_table( 3 uname => 'jy', 4 tname => 'salestable', 5 options_flag => DBMS_REDEFINITION.CONS_USE_ROWID, 6 part_name => 'sal10q1, sal10q2'); 7 end; 8 / PL/SQL procedure successfully completed.
3.在新表空間example中創(chuàng)建中間表。因為這是對分區(qū)執(zhí)行聯(lián)機(jī)重定義,因此中間表不能是分區(qū)表。
SQL> create table jy.int_salestb1 2 (s_productid number, 3 s_saledate date, 4 s_custid number, 5 s_totalprice number) 6 tablespace example; Table created. SQL> create table jy.int_salestb2 2 (s_productid number, 3 s_saledate date, 4 s_custid number, 5 s_totalprice number) 6 tablespace example; Table created.
4.使用rowid方法來執(zhí)行重定義操作
SQL> begin 2 dbms_redefinition.start_redef_table( 3 uname => 'jy', 4 orig_table => 'salestable', 5 int_table => 'int_salestb1, int_salestb2', 6 col_mapping => NULL, 7 options_flag => DBMS_REDEFINITION.CONS_USE_ROWID, 8 part_name => 'sal10q1, sal10q2', 9 continue_after_errors => TRUE); 10 end; 11 / PL/SQL procedure successfully completed.
注意,part_name參數(shù)用來指定所有要重定義的分區(qū),int_table參數(shù)用來指定每個分區(qū)所對應(yīng)的中間表,continue_after_errors參數(shù)被設(shè)置為true,因此重定義操作即使當(dāng)某個特定分區(qū)遇到錯誤也會繼續(xù)執(zhí)行。
5.在中間表上創(chuàng)建任何本地索引
SQL> create index jy.int_sales1_index on jy.int_salestb1 2 (s_saledate, s_productid, s_custid) 3 tablespace example; Index created. SQL> create index jy.int_sales2_index on jy.int_salestb2 2 (s_saledate, s_productid, s_custid) 3 tablespace example; Index created.
6.可選操作同步中間表
SQL> begin 2 dbms_redefinition.sync_interim_table( 3 uname => 'jy', 4 orig_table => 'salestable', 5 int_table => 'int_salestb1, int_salestb2', 6 part_name => 'sal10q1, sal10q2', 7 continue_after_errors => TRUE); 8 end; 9 / PL/SQL procedure successfully completed.
7.完成重定義操作
SQL> begin 2 dbms_redefinition.finish_redef_table( 3 uname => 'jy', 4 orig_table => 'salestable', 5 int_table => 'int_salestb1, int_salestb2', 6 part_name => 'sal10q1, sal10q2', 7 continue_after_errors => TRUE); 8 end; 9 / PL/SQL procedure successfully completed.
8.可選操作,查詢dba_redefinition_status視圖來確保對每個分區(qū)都重定義操作成功
SQL> select base_table_owner, base_table_name, operation, status from dba_redefinition_status; no rows selected
如果有任何分區(qū)重定義失敗,視圖dba_redefinition_errors會顯示出錯誤原因,修正故障重新執(zhí)行聯(lián)機(jī)重定義操作。
下面的查詢顯示了表jy.salestable有兩個分區(qū)已經(jīng)移動到了新的表空間example中了
SQL> select partition_name, tablespace_name from dba_tab_partitions where table_name = 'SALESTABLE' and table_owner='JY'; PARTITION_NAME TABLESPACE_NAME -------------------------------------------------------------------------------- ------------------------------ SAL10Q1 EXAMPLE SAL10Q2 EXAMPLE SAL10Q3 USERS SAL10Q4 USERS
到此聯(lián)機(jī)重定義操作完成
到此,相信大家對“Oracle12.2怎么將分區(qū)移動到不同的表空間中”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。