本文共 1887 字,大约阅读时间需要 6 分钟。
在实际操作中,导入数据时遇到了一个问题:当使用imp导入数据时,触发器报错退出,导致存储过程、触发器、函数等对象未被导入。为了解决这个问题,我们采取了以下步骤进行验证和处理。
测试环境:CentOS 6.7 + Oracle 11.2.0.4
实验步骤如下:
导出Scott用户的表和数据
exp scott/tiger OWNER=scott BUFFER=10240000 STATISTICS=none RESUMABLE=y FILE=scott_exp.dmp LOG=scott_exp.log
创建Scott用户的过程、函数、触发器
create or replace procedure pro_insert_dept isbegininsert into dept values (99, 'xx_dept_name', 'Beijing');end;
create or replace function sp_fun1(spName varchar2) return number isyearSal number(7, 2);beginselect sal * 12 + nvl(comm, 0) * 12 into yearSal from emp where ename = spName;return yearSal;end;
-- 创建序列create sequence seq_del_id;-- 创建表create table emp_del_info(autoid number primary key,deptno number,empno number,ename varchar2(20),del_rq date);-- 创建触发器create or replace trigger trg_del_emp_infobefore delete on empfor each rowdeclarebegininsert into emp_del_info(autoid,deptno,empno,ename,del_rq)values(seq_del_id.nextval, :old.deptno, :old.empno, :old.ename, sysdate);end;
导出Scott用户的元数据
exp scott/tiger OWNER=scott ROWS=n BUFFER=10240000 STATISTICS=none RESUMABLE=y FILE=scott_metadata_exp.dmp LOG=scott_metadata_exp.log
删除Scott用户
select 'alter system kill session '''||sid||','||serial#||''''||';' from v$session where username='SCOTT';
drop user scott cascade;
重新创建Scott用户并导入表和数据
create user scott identified by tiger default tablespace users;grant connect, resource to scott;
imp scott/tiger BUFFER=10240000 RESUMABLE=y FILE=scott_exp.dmp LOG=imp_scott_exp.log IGNORE=y FULL=y
导入Scott用户的元数据
imp scott/tiger BUFFER=10240000 RESUMABLE=y FILE=scott_metadata_exp.dmp LOG=imp_scott_metadata_exp.log IGNORE=y FULL=y
经过以上操作,验证发现:
最终结论:通过分阶段导出和导入,确保了数据和元数据的完整性,没有对已有表数据造成覆盖。
转载地址:http://iepfk.baihongyu.com/