博客
关于我
Oracle数据库验证IMP导入元数据是否会覆盖历史表数据
阅读量:793 次
发布时间:2023-02-25

本文共 1887 字,大约阅读时间需要 6 分钟。

在实际操作中,导入数据时遇到了一个问题:当使用imp导入数据时,触发器报错退出,导致存储过程、触发器、函数等对象未被导入。为了解决这个问题,我们采取了以下步骤进行验证和处理。

测试环境:CentOS 6.7 + Oracle 11.2.0.4

实验步骤如下:

  • 导出Scott用户的表和数据

    • 由于此时Scott用户没有触发器、过程、函数等对象,我们直接使用exp工具导出相关表数据。
    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 is
    begin
    insert into dept values (99, 'xx_dept_name', 'Beijing');
    end;
    • 创建函数:
    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;
    • 创建触发器:
    -- 创建序列
    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
    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;
  • 导出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用户

    • 首先确认是否有Scott用户的登录会话:
    select 'alter system kill session '''||sid||','||serial#||''''||';' from v$session where username='SCOTT';
    • 如果有会话,执行上述SQL命令终止会话。
    • 删除用户:
    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/

    你可能感兴趣的文章
    Oracle BMW Racing sailing vessel帆船图
    查看>>
    ORACLE Bug 4431215 引发的血案—原因分析篇
    查看>>
    Oracle cmd乱码
    查看>>
    Oracle Corp甲骨文公司推出Oracle NoSQL数据库2.0版
    查看>>
    oracle dblink 创建使用 垮库转移数据
    查看>>
    oracle dblink结合同义词的用法 PLS-00352:无法访问另一数据库
    查看>>
    Oracle dbms_job.submit参数错误导致问题(ora-12011 无法执行1作业)
    查看>>
    oracle dg switchover,DG Switchover fails
    查看>>
    Oracle E-Business Suite软件 任意文件上传漏洞(CVE-2022-21587)
    查看>>
    Oracle EBS OPM 发放生产批
    查看>>
    Oracle EBS-SQL (BOM-15):检查多层BOM(含common BOM).sql
    查看>>
    Oracle EBS环境下查找数据源(OAF篇)
    查看>>
    oracle Extract 函数
    查看>>
    uni-app开发环境自动部署的一个误区(App running at...)
    查看>>
    Oracle GoldenGate Director安装和配置(无图)
    查看>>
    oracle instr函数详解
    查看>>
    Oracle Java所有版本的下载链接
    查看>>
    oracle ogg 单实例双向复制搭建(oracle-oracle)--Oracle GoldenGate
    查看>>
    oracle ORA-14402 OGG-01296
    查看>>
    oracle partition by list,深入解析partition-list 分区
    查看>>