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

后端 未结 6 831
清酒与你
清酒与你 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:38

    --MOVING ALL TABLES FROM USER  
    BEGIN
      FOR i IN (
        SELECT * FROM ALL_tables where owner = :owner 
          and (tablespace_name is null or tablespace_name != :tbs)
          and temporary != 'Y'
          and partitioned != 'YES'
        ) LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE '  || i.table_name || ' MOVE TABLESPACE ' || :tbs;
      END LOOP; 
    END;
    
    
    --MOVING ALL INDEX
    
     BEGIN
      FOR i IN (
        SELECT * FROM ALL_tab_partitions 
        WHERE table_owner = :owner and tablespace_name != :tbs
      ) LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE ' 
          || i.table_name || ' MOVE PARTITION '
          || i.partition_name ||' TABLESPACE '|| :tbs;
      END LOOP;
    END;
    
    
    --MOVING ALL PARTATION TABLES FROM USER  
    
    BEGIN
      FOR i IN (
        SELECT * FROM ALL_tables where owner = :owner and partitioned = 'YES'
      ) LOOP
        EXECUTE IMMEDIATE 'ALTER TABLE '
          || i.table_name || ' MODIFY DEFAULT ATTRIBUTES TABLESPACE ' || :tbs;
      END LOOP;
    END;
    

提交回复
热议问题