How do you move a partitioned table from one tablespace to another in Oracle 11g?

后端 未结 6 825
清酒与你
清酒与你 2021-02-04 15:16

I have a partitioned table that belongs to tablespace report. I want to move it to tablespace record instead.

One possibility is to drop the table and

6条回答
  •  既然无缘
    2021-02-04 15:45

        
    PROCEDURE P_ALTER_TABLE_SPACE(
            A_TNAME         IN VARCHAR2,
            A_DESTTS        IN VARCHAR2,
            A_PATITION_TYPE IN VARCHAR2)
        IS
          CURSOR PCUR(VTNAME VARCHAR2, VTSPNAME VARCHAR2)
          IS
            SELECT TABLE_NAME,
              PARTITION_NAME
            FROM USER_TAB_PARTITIONS
            WHERE TABLE_NAME = VTNAME
            AND TABLESPACE_NAME NOT LIKE VTSPNAME
            ORDER BY PARTITION_POSITION DESC;
    
          CURSOR PCURR(VTNAME VARCHAR2, VTSPNAME VARCHAR2)
          IS
            SELECT TABLE_NAME,
              SUBPARTITION_NAME
            FROM USER_TAB_SUBPARTITIONS
            WHERE TABLE_NAME = VTNAME
            AND TABLESPACE_NAME NOT LIKE VTSPNAME
            ORDER BY SUBPARTITION_POSITION DESC;
        BEGIN
          IF A_PATITION_TYPE = 'PARTITION' THEN
            FOR PROW IN PCUR(A_TNAME, A_DESTTS)
            LOOP
              SQLSTMNT := 'ALTER TABLE '||PROW.TABLE_NAME|| ' MOVE PARTITION '||PROW.PARTITION_NAME|| ' TABLESPACE '||A_DESTTS;
              EXECUTE IMMEDIATE SQLSTMNT;
            END LOOP;
          ELSE
            FOR PROW IN PCURR(A_TNAME, A_DESTTS)
            LOOP
              SQLSTMNT := 'ALTER TABLE '||PROW.TABLE_NAME|| ' MOVE SUBPARTITION '||PROW.SUBPARTITION_NAME|| ' TABLESPACE '||A_DESTTS;
              EXECUTE IMMEDIATE SQLSTMNT;
            END LOOP;
          END IF;
        END P_ALTER_TABLE_SPACE;
        

提交回复
热议问题