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
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;