簡體   English   中英

創建具有百萬條記錄的備份表

[英]create a backup table with million records

我想將舊記錄從TABLEA移到TABLEA_AUDIT。 TABLEA大約有150萬條記錄,並且有兩個嵌套表。

記錄數:1557951大小:1024 MB

我嘗試過

1.使用Create table作為select * from

CREATE TABLE
TABLEA_AUDIT
COLUMN TABLEA_STAGE NOT SUBSTITUTABLE AT ALL LEVELS
NESTED TABLE TABLEA_STAGES STORE AS AUDIT_TABLEA_STAGES,
NESTED TABLE TABLEA_MODELS STORE AS AUDIT_TABLEA_MODELS
AS
SELECT *
FROM
TABLEA
WHERE COULMN1 IS NOT NULL
AND TRUNC(UPDATED_DT) < '01-MAR-18';

結果:2小時的等待,沒有得到任何結果

2.通過在博客下面關注來嘗試創建CREATE TABLE AS,而無需記錄日志。 http://www.dba-oracle.com/t_fast_copy_data_oracle_table.htm

結果:2小時的等待,沒有得到任何結果

3.開發了一個新過程來復制記錄並創建了一個新的DBMS_JOB

EXECUTE IMMEDIATE 'CREATE TABLE TABLEA_AUDIT AS SELECT * FROM TABLEA';

結果:作業運行超過2小時,沒有結果。

4,創建表並開發程序以插入批量記錄

set serveroutput on size unlimited
set timing on
declare 
type audit_type is table of TABLEA%rowtype;
v_type audit_type;
CURSOR temp_cur is
select  *
FROM TABLEA a
WHERE COLUMN1 IS NOT NULL
AND TRUNC(UPDATED_DT) < '01-MAR-18';
BEGIN

    OPEN  temp_cur;
    / collect data in the collection /
    FETCH temp_cur BULK COLLECT INTO v_type;
    / close the pointer /
    CLOSE temp_cur;

    FORALL i in v_type.first .. v_type.last
    INSERT INTO TABLEA_AUDIT VALUES v_type(i);

    FORALL i in v_type.first .. v_type.last
    DELETE  FROM TABLEA WHERE PRIMARY_KEY_COL = v_type(i).PRIMARY_KEY_COL;               

    COMMIT;
END;
/

謝謝。

兄弟試試這個

--MSSQL
    select * into TABLEA_AUDIT from TABLEA

--FOR oracle (large amount of data )
Create table TABLEA_AUDIT
As
Select * 
from TABLEA 
where 1=2;

Insert into TABLEA_AUDIT
Select * from TABLEA;

我建議數據泵

首先,使用導出數據泵導出表。 在下一步中,使用REMAP_TABLE參數導入(使用“導入數據泵-誰猜?”)。

這是一個基於Scott的EMP表的簡單示例(為了方便閱讀,我刪除了多余的行):

出口:

c:\Temp>expdp scott/tiger@xe tables=emp directory=ext_dir dumpfile=emp.dmp

Export: Release 11.2.0.2.0 - Production on Pon Tra 30 14:45:18 2018

Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/********@xe tables=emp directory=ext_dir dumpfile=emp.dmp
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SCOTT"."EMP"                               8.484 KB      12 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
  C:\TEMP\EMP.DMP
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 14:45:20


c:\Temp>

進口:

c:\Temp>impdp scott/tiger@xe remap_table=emp:emp_bkp directory=ext_dir dumpfile=emp.dmp exclude=constraint

Import: Release 11.2.0.2.0 - Production on Pon Tra 30 14:50:09 2018

Master table "SCOTT"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_FULL_01":  scott/********@xe remap_table=emp:emp_bkp directory=ext_dir dumpfile=emp.dmp exc
lude=constraint
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."EMP_BKP"                           8.484 KB      12 rows
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
ORA-31684: Object type INDEX:"SCOTT"."PK_EMP" already exists
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
ORA-39111: Dependent object type INDEX_STATISTICS skipped, base object type INDEX:"SCOTT"."PK_EMP" already exists
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SCOTT"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 14:50:11


c:\Temp>

請注意,主鍵約束創建失敗,因為具有該名稱的約束已存在於原始表中。

結果:

c:\Temp>sqlplus scott/tiger@xe

SQL> select * From emp_Bkp;

     EMPNO ENAME      JOB              MGR HIREDATE          SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17.12.1980        800                    20
      7499 ALLEN      SALESMAN        7698 20.02.1981       1600        300         30
      7521 WARD       SALESMAN        7698 22.02.1981       1250        500         30
      7566 JONES      MANAGER         7839 02.04.1981       2975                    20
      7654 MARTIN     SALESMAN        7698 28.09.1981       1250       1400         30
      7698 BLAKE      MANAGER         7839 01.05.1981       2850                    30
      7782 CLARK      MANAGER         7839 09.06.1981       2450                    10
      7839 KING       PRESIDENT            17.11.1981       5000                    10
      7844 TURNER     SALESMAN        7698 08.09.1981       1500          0         30
      7900 JAMES      CLERK           7698 03.12.1981        950                    30
      7902 FORD       ANALYST         7566 03.12.1981       3000                    20
      7934 MILLER     CLERK           7782 23.01.1982       1300                    10

12 rows selected.

SQL>

再次,您應該使用兩個命令:

expdp scott/tiger@xe tables=emp directory=ext_dir dumpfile=emp.dmp

impdp scott/tiger@xe remap_table=emp:emp_bkp directory=ext_dir dumpfile=emp.dmp exclude=constraint

試試看,看看它是如何工作的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM