阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Oracle数据库验证IMP导入元数据是否会覆盖历史表数据

122次阅读
没有评论

共计 2049 个字符,预计需要花费 6 分钟才能阅读完成。

场景:imp 导入数据时,最终触发器报错退出,并未导入存储过程、触发器、函数。
现在 exp 单独导出元数据,然后 imp 导入元数据,验证是否会影响已导入的表数据。

测试环境:CentOS 6.7 + Oracle 11.2.0.4
构造实验环境:

  • 1. 导出 scott 用户的表和数据
  • 2.scott 用户创建过程、函数、触发器
  • 3. 导出 scott 元数据
  • 4. 删除 scott 用户
  • 5. 导入 scott 表和数据
  • 6. 导入 Scott 元数据

1. 导出 scott 用户的表和数据

导出 scott 用户的表和数据,此时并没有触发器、过程、函数这些对象:

 exp scott/tiger OWNER=scott BUFFER=10240000 STATISTICS=none RESUMABLE=y FILE=scott_exp.dmp LOG=scott_exp.log 

2.scott 用户创建过程、函数、触发器

scott 用户创建过程:

create or replace procedure pro_insert_dept is
begin
  insert into dept values (99, 'xx_dept_name', 'Beijing');
end;
/

scott 用户创建函数:

create or replace function sp_fun1(spName varchar2) return number is
yearSal number(7, 2);
begin
select sal * 12 + nvl(comm, 0) * 12 into yearSal from emp where ename = spName; return yearSal;
end;
/

scott 用户触发器:

-- 创建序列 
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_info
  BEFORE DELETE
  ON emp
  FOR EACH ROW
  DECLARE
    -- local variables here
  BEGIN
    INSERT INTO emp_del_info(autoid,deptno,empno,ename,del_rq)
          VALUES(seq_del_id.NEXTVAL,:OLD.deptno,:OLD.empno,:OLD.ename,sysdate);
  END;
/

3. 导出 scott 元数据

导出 scott 元数据:

 exp scott/tiger OWNER=scott ROWS=n BUFFER=10240000 STATISTICS=none RESUMABLE=y FILE=scott_metadata_exp.dmp LOG=scott_metadata_exp.log 

此时导出的元数据,是有触发器、过程、函数这些对象的。

4. 删除 scott 用户

确认没有 scott 用户登录的 session:

 

select 'alter system kill session'''||sid||','||serial#||''''||';' from v$session where username='SCOTT';

如果上述查询有结果,那么直接把查出的结果复制执行即可 kill 掉 scott 用户登录的 session。

删除 scott 用户:

SQL>  drop user scott cascade;

User dropped.

5. 导入 scott 表和数据

先创建用户并赋权:

SQL> create user scott identified by tiger default tablespace users;

User created.

SQL> grant connect, resource to scott;

Grant succeeded.

导入表和数据:

imp scott/tiger BUFFER=10240000 RESUMABLE=y FILE=scott_exp.dmp LOG=imp_scott_exp.log IGNORE=y FULL=y

此时导入的只是表和表数据,没有触发器、过程、函数这些对象。

6. 导入 Scott 元数据

 

imp scott/tiger BUFFER=10240000 RESUMABLE=y FILE=scott_metadata_exp.dmp LOG=imp_scott_metadata_exp.log IGNORE=y FULL=y

此时导入的只是表结构、触发器、过程、函数等这些对象,
最后验证下是否覆盖上一步已导入的表数据?
最终结论是没有覆盖已导入的表数据,之前未导入的过程、函数、触发器也都成功导入。

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-06/132474.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计2049字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中