在进行oracle导出导入数据时,遇到一些坑,总结下:
1.exp-00056 1455
原因:有编译未通过的视图,重新编译或者将其删除
(https://blog.csdn.net/dragoo1/article/details/54587381)
2.oracle导出后发现少表,同时在查空表数量的时候发现num_rows=0查不到结果
原因:num_rows=0查不到结果是因为user_tables中的num_rows字段的数据不是实时的
在参考https://blog.csdn.net/chfyljt/article/details/80623078和https://www.cnblogs.com/ningvsban/p/3603678.html后,
写了一个package来解决这个问题
create or replace package myutil_pkg as
--定义通用的字符串数组参数类型(传入或返回参数)
type tab_str is table of varchar2(30);
/**
* 获取当前数据库的表的统计数据(非空表、空表、所有表的数量)
* 用来验证刷新统计数据操作是否成功
**/
--使用示例:select * from table(myutil_pkg.tab_status);
function tab_status return tab_str pipelined;
/**
* 刷新user_tables中的统计数据
* 解决user_tables中num_rows查不出来的问题
**/
--使用示例:
/**
* begin
* myutil_pkg.statistics_all_tab;
* end;
*
* 可以用 select * from table(myutil_pkg.tab_status);
* 验证刷新统计数据操作是否成功
*/
procedure statistics_all_tab;
/**
* 给需要做导出操作的数据库,其中的空表分配空间(如果空表没有分配空间的话)
**/
--使用示例:
/**
* begin
* myutil_pkg.distribExtent;
* end;
*/
procedure distribExtent;
end myutil_pkg;
create or replace package body myutil_pkg as
/**
* 获取当前数据库的表的统计数据(非空表、空表、所有表的数量)
**/
function tab_status return tab_str pipelined
as
v_ret varchar2(500);
tmp_num number;
begin
select count(*) into tmp_num from user_tables where num_rows != 0; --非空表
v_ret:='非空表:'||tmp_num;
pipe row(v_ret);
select count(*) into tmp_num from user_tables where num_rows = 0; --空表
v_ret:='空表:'||tmp_num;
pipe row(v_ret);
select count(*) into tmp_num from user_tables; --表的总数
v_ret:='总数:'||tmp_num;
pipe row(v_ret);
end tab_status;
/**
* 刷新user_tables中的统计数据
* https://blog.csdn.net/chfyljt/article/details/80623078
**/
procedure statistics_all_tab as
begin
for rs in (select ut.table_name from user_tables ut) loop
execute immediate 'analyze table '||rs.table_name||' compute statistics';
end loop;
exception
when others then
dbms_output.put_line('errm statistics_all_tab:'||sqlerrm);
end statistics_all_tab;
/**
* 给需要做导出操作的数据库,其中的空表分配空间(如果空表没有分配空间的话)
* https://www.cnblogs.com/ningvsban/p/3603678.html
**/
procedure distribExtent as
begin
for rs in (select ut.table_name from user_tables ut) loop
execute immediate 'alter table '||rs.table_name||' allocate extent';
end loop;
exception
when others then
dbms_output.put_line('errm statistics_all_tab:'||sqlerrm);
end distribExtent;
end myutil_pkg;