oracle 11不能导出空表的详细解决方法
第一步:分别执行下面两句话
select t.table_name,t.num_rows from user_tables t
select table_name from user_tables where NUM_ROWS=0;
若查询的空表数相同
第二步:对比查询结果,若查询的空表数(行数为0)是否相同,若相同则执行下面语句:
1.先找出空表
select ‘alter table ‘||table_name||’ allocate extent;’ from user_tables where num_rows=0
2. 对空表执行容量替换,即执行下面sql语句,例如(红字为要替换的表名):
alter table TBL_1 allocate extent;
alter table TBL_2 allocate extent;
alter table TBL_3 allocate extent;
alter table TBL_4 allocate extent;
……
第三步:若空表数量不相同,则表明库表不是实时,用num_rows 统计不准确,要用下面方法:
1、创建一个函数:
create or replace function count_rows(table_name in varchar2,
owner in varchar2 default null)
return number
authid current_user
IS
num_rows number;
stmt varchar2(2000);
begin
if owner is null then
stmt := ‘select count() from “’||table_name||’”’;
else
stmt := 'select count() from "’||owner||’"."’||table_name||’"’;
end if;
execute immediate stmt into num_rows;
return num_rows;
end;
2、执行下面语句,找出实际空表数
select table_name, count_rows(table_name) nrows from user_tables order by nrows
3、对空表执行容量替换,即执行下面sql语句,例如(红字为要替换的表名):
alter table TBL_1 allocate extent;
alter table TBL_2 allocate extent;
alter table TBL_3 allocate extent;
alter table TBL_4 allocate extent;