zoukankan      html  css  js  c++  java
  • 创建外部表例子

    创建外部表例子

    The following SQL statements create an external table named admin_ext_
    employees in the hr schema and load data from the external table into

    the hr.employees table.

    CONNECT  /  AS SYSDBA;

    -- Set up directories and grant access to hr
    CREATE OR REPLACE DIRECTORY admin_dat_dir
        AS '/flatfiles/data';
    CREATE OR REPLACE DIRECTORY admin_log_dir
        AS '/flatfiles/log';
    CREATE OR REPLACE DIRECTORY admin_bad_dir
        AS '/flatfiles/bad';

    GRANT READ ON DIRECTORY admin_dat_dir TO hr;
    GRANT WRITE ON DIRECTORY admin_log_dir TO hr;
    GRANT WRITE ON DIRECTORY admin_bad_dir TO hr;

    -- hr connects. Provide the user password (hr) when prompted.
    CONNECT hr

    -- create the external table
    CREATE TABLE admin_ext_employees
                       (employee_id       NUMBER(4),
                        first_name        VARCHAR2(20),
                        last_name         VARCHAR2(25),
                        job_id            VARCHAR2(10),
                        manager_id        NUMBER(4),
                        hire_date         DATE,
                        salary            NUMBER(8,2),
                        commission_pct    NUMBER(2,2),
                        department_id     NUMBER(4),
                        email             VARCHAR2(25)
                       )
         ORGANIZATION EXTERNAL
         (
           TYPE ORACLE_LOADER
           DEFAULT DIRECTORY admin_dat_dir
           ACCESS PARAMETERS
           (
             records delimited by newline
             badfile admin_bad_dir:'empxt%a_%p.bad'
             logfile admin_log_dir:'empxt%a_%p.log'
             fields terminated by ','
             missing field values are null
             ( employee_id, first_name, last_name, job_id, manager_id,
               hire_date char date_format date mask "dd-mon-yyyy",
               salary, commission_pct, department_id, email
             )
           )
           LOCATION ('empxt1.dat', 'empxt2.dat')
         )
         PARALLEL
         REJECT LIMIT UNLIMITED;

    -- enable parallel for loading (good if lots of data to load)
    ALTER SESSION ENABLE PARALLEL DML;

    -- load the data in hr employees table
    INSERT INTO employees (employee_id, first_name, last_name, job_id,

    manager_id,
                           hire_date, salary, commission_pct,

    department_id, email)
                SELECT * FROM admin_ext_employees;

    查询结果:

    SQL>    SELECT * FROM admin_ext_employees;

                                                                                                                                                                               Database Freespace Summary

            361 Mark                 Jasper                    SA_REP            145 17-MAY-01       8000             .1            80 mjasper
            362 Brenda               Starr                     AD_ASST           200 17-MAY-01       5500              0            10 bstarr
            363 Alex                 Alda                      AC_MGR            145 17-MAY-01       9000            .15            80 aalda
            402 Abby                 Applegate                 IT_PROG           103 17-MAY-01       9000             .2            60 aapplega
            403 Carol                Cousins                   AD_VP             100 17-MAY-01      27000             .3            90 ccousins
            404 John                 Richardson                AC_ACCOUNT        205 17-MAY-01       5000              0           110 jrichard

    6 rows selected.

    SQL>

  • 相关阅读:
    PyQt(Python+Qt)学习随笔:containers容器类部件QStackedWidget重要方法介绍
    什么叫工业4.0,这篇接地气的文章终于讲懂了
    怎样 真正认识一个 人
    华为的绩效管理:减人、增 效、加薪
    羽毛球战术
    魔方教程
    员工培养:事前指导,事后纠正
    一把手瞄准哪里,核心竞争力就在哪里
    海尔的五次战略变革
    如何提高基层员工的执行力
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3194215.html
Copyright © 2011-2022 走看看