zoukankan      html  css  js  c++  java
  • EXPDP如何导出两表关联后的数据

    以SCOTT用户的EMP表为例,说明如何使用QUERY选项导出两个表关联后的数据

    1. 检查EMP表的empno值
    SQL> select empno from emp order by 1;

         EMPNO
    ----------
          7369
          7499
          7521
          7566
          7654
          7698
          7782
          7788
          7839
          7844
          7876
          7900
          7902
          7934
    14 rows selected.
    SQL>
    2.创建测试表TEST01,并插入部分数据:
    SQL>create table test01 (name varchar2(30),empno number(8));
    SQL>
    insert into test01 values ('test1',7788);
    insert into test01 values ('test2',7900);
    insert into test01 values ('test3',8999);
    commit;

    3.需要导出下面SQL对应的EMP表的数据:
    select * from emp t1 where exists (select EMPNO from test01 t2 where t2.empno=t1.empno);
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30

    4. 使用EXPDP导出数据:
    $expdp scott/tiger directory=dump_dir dumpfile=emp.dmp tables=emp query='emp:" where exists (select EMPNO from test01 where ku$.EMPNO = test01.EMPNO)"'
    . . exported "SCOTT"."EMP"                               8.070 KB       2 rows
    Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
    ******************************************************************************

    5.说明:
    这里需要使用ku$作为表的别名,否则表的所有记录都会被导出。

    相关参考:
    https://docs.oracle.com/database/121/SUTIL/GUID-CDA1477D-4710-452A-ABA5-D29A0F3E3852.htm#SUTIL860

  • 相关阅读:
    三、python函数基础
    二、python算法逻辑基础
    RE正则表达式-语法
    read方法读取ini文件报错'gbk' codec can't decode
    git bash常用命令
    xlrd、xlwt、xlutils模块操作excel文件
    Git命令行克隆项目
    浏览器console,web自动化常用的几种定位调试使用方法总结
    css定位正则匹配和模糊匹配
    罗马数字转整数
  • 原文地址:https://www.cnblogs.com/binliubiao/p/8856659.html
Copyright © 2011-2022 走看看