1. 程式人生 > >Oracle批量處理空表、匯出空表

Oracle批量處理空表、匯出空表

1.insert一行,再rollback就產生segment了

    該方法是在在空表中插入資料,再刪除,則產生segment。匯出時則可匯出空表。

2.批量處理空表
        (1) 查詢當前使用者下的所有空表

 select table_name from user_tables where num_rows='0';

        (2) 用以下SQL語句執行查詢

 select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;

        假設我們這裡有空表TABLE_1,TABLE_2,TABLE_3,TABLE_4,則查詢結果如下:

alter table TABLE_1 allocate extent;
alter table TABLE_2 allocate extent;
alter table TABLE_3 allocate extent;
alter table TABLE_4 allocate extent;

        (3) 把上面的 alter SQL語句執行就可以了
        (4) 再查詢當前使用者下的所有空表,這時應該就沒有空表了
        select 'analyze table '||table_name||' compute statistics;' from user_tables;
        select table_name from user_tables where num_rows='0';