-- 查询所有未分配segment的空表
SELECT 'ALTER TABLE ' || table_name || ' ALLOCATE EXTENT;'
FROM user_tables
WHERE num_rows = 0 OR num_rows IS NULL
AND segment_created = 'NO';
-- 执行查询结果中的所有ALTER语句
--如果有要剔除的临时表会话表,可以微调
select 'alter table '||table_name||' allocate extent;'
from user_tables a
where (num_rows=0 or num_rows is null ) and (table_name not like 'SESSION%') and tablespace_name is not null and not exists(
select 1 from user_part_tables b where a.TABLE_NAME=b.table_name
)
3. 修改数据库参数(适用于 11g 及以上版本)
-- 临时修改(立即生效,重启后失效)
ALTER SYSTEM SET deferred_segment_creation=FALSE;
-- 永久修改(需要重启数据库)
ALTER SYSTEM SET deferred_segment_creation=FALSE SCOPE=SPFILE;