CASE6

1. SQL脚本

[oracle@node3 ulcase]$ cat ulcase6.sql

set termout off
rem host write sys$output "Building case 6 demonstration tables. Please wait" drop table emp; create table emp
(empno number(4) not null,
ename char(10),
job char(9),
mgr number(4),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2)); create unique index empix on emp(empno); exit

2. 控制文件

[oracle@node3 ulcase]$ cat ulcase6.ctl

-- Copyright (c) 1991, 2004 Oracle.  All rights reserved.
-- NAME
-- ulcase6.ctl - SQL*Loader Case Study 6: Loading Data Using the
-- Direct Path Load Method
--
-- DESCRIPTION
-- This case study demonstrates the following:
-- Use of the direct path load method to load and index data.
--
-- How to specify the indexes for which the data is presorted.
--
-- Use of the NULLIF clause.
--
-- Loading all-blank numeric fields as NULL.
--
-- TO RUN THIS CASE STUDY:
-- 1. Before executing this control file, log in to SQL*Plus as
-- scott/tiger. Enter @ulcase6 to execute the SQL script for
-- this case study. This prepares and populates tables and
-- then returns you to the system prompt.
--
-- 2. At the system prompt, invoke the case study as follows:
-- sqlldr USERID=scott/tiger CONTROL=ulcase6.ctl LOG=ulcase6.log DIRECT=TRUE
--
-- NOTES ABOUT THIS CONTROL FILE
-- The SORTED INDEXES statement identifies the indexes on which
-- the data is sorted. This statement indicates that the datafile
-- is sorted on the columns in the empix index. It allows
-- SQL*Loader to optimize index creation by eliminating the sort
-- phase for this data when using the direct path load method.
--
-- The NULLIF...BLANKS clause specifies that the column should
-- be loaded as NULL if the field in the datafile consists of
-- all blanks.
--
LOAD DATA
INFILE 'ulcase6.dat'
REPLACE
INTO TABLE emp
SORTED INDEXES (empix)
(empno POSITION(1:4),
ename POSITION(6:15),
job POSITION(17:25),
mgr POSITION(27:30) NULLIF mgr=blanks,
sal POSITION(32:39) NULLIF sal=blanks,
comm POSITION(41:48) NULLIF comm=blanks,
deptno POSITION(50:51) NULLIF empno=blanks)

3. 数据文件

[oracle@node3 ulcase]$ cat ulcase6.dat

7499 ALLEN      SALESMAN  7698  1600.00   300.00 30
7566 JONES MANAGER 7839 3123.75 20
7654 MARTIN SALESMAN 7698 1312.50 1400.00 30
7658 CHAN ANALYST 7566 3450.00 20
7782 CLARK MANAGER 7839 2572.50 10
7839 KING PRESIDENT 5500.00 10
7934 MILLER CLERK 7782 920.00 10

执行后结果:

[oracle@node3 ulcase]$ sqlplus scott/tiger @ulcase6.sql

[oracle@node3 ulcase]$ sqlldr userid=scott/tiger control=ulcase6.ctl direct=yes

--注意,上述命令多了一个参数direct=yes,代表直接路径插入

SQL> select * from emp;

EMPNO ENAME     JOB         MGR  HIREDATE     SAL  COMM  DEPTNO
----- ---------- --------- ----- --------- ------- ----- ------
7499 ALLEN SALESMAN 7698 1600 300 30
7566 JONES MANAGER 7839 3124 20
7654 MARTIN SALESMAN 7698 1313 1400 30
7658 CHAN ANALYST 7566 3450 20
7782 CLARK MANAGER 7839 2573 10
7839 KING PRESIDENT 5500 10
7934 MILLER CLERK 7782 920 10 7 rows selected.

查看日志文件:

[oracle@node3 ulcase]$ vim ulcase6.log

SQL*Loader: Release 11.2.0.1.0 - Production on Fri Sep 19 02:49:21 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Control File:   ulcase6.ctl
Data File: ulcase6.dat
Bad File: ulcase6.bad
Discard File: none specified (Allow all discards) Number to load: ALL
Number to skip: 0
Errors allowed: 50
Continuation: none specified
Path used: Direct Table EMP, loaded from every logical record.
Insert option in effect for this table: REPLACE Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
EMPNO 1:4 4 CHARACTER
ENAME 6:15 10 CHARACTER
JOB 17:25 9 CHARACTER
MGR 27:30 4 CHARACTER
NULL if MGR = BLANKS
SAL 32:39 8 CHARACTER
NULL if SAL = BLANKS
COMM 41:48 8 CHARACTER
NULL if COMM = BLANKS
DEPTNO 50:51 2 CHARACTER
NULL if EMPNO = BLANKS The following index(es) on table EMP were processed:
index SCOTT.EMPIX loaded successfully with 7 keys Table EMP:
7 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null. Bind array size not used in direct path.
Column array rows : 5000
Stream buffer bytes: 256000
Read buffer bytes: 1048576 Total logical records skipped: 0
Total logical records read: 7
Total logical records rejected: 0
Total logical records discarded: 0
Total stream buffers loaded by SQL*Loader main thread: 1
Total stream buffers loaded by SQL*Loader load thread: 0 Run began on Fri Sep 19 02:49:21 2014
Run ended on Fri Sep 19 02:49:27 2014 Elapsed time was: 00:00:06.66
CPU time was: 00:00:01.27

注意:在本例中

1> SORTED INDEXES (empix)指明数据文件的数据是按照索引empix对应的列排过序的,只有在直接路径插入下有效,即sqlldr命令中需指明direct=yes,这样可极大提高插入效率。

2> NULLIF...BLANKS子句指明列对应数据文件的位置如果是空格的话,当null处理。

SQL*Loader之CASE6的更多相关文章

  1. SQL*LOADER错误总结

    在使用SQL*LOADER装载数据时,由于平面文件的多样化和数据格式问题总会遇到形形色色的一些小问题,下面是工作中累积.整理记录的遇到的一些形形色色错误.希望能对大家有些用处.(今天突然看到自己以前整 ...

  2. Bulkcopy对应的实现是Oracle的SQL*LOADER,期间造成Index Unusable,并且last_ddl_time上是不体现的

    部分项目反馈系统整体突然变慢,经查询发现一个系统核心的大数据表的索引状态全部是Unusable. 导致索引失效的直接原因:当某些操作导致数据的rowid改变,索引就会完全失效. 那什么时候会导致row ...

  3. SQL*Loader之CASE11

    CASE11 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase11.sql set termout off rem host write sys$output &q ...

  4. SQL*Loader之CASE10

    CASE10 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase10.sql rem host write sys$output "Building dem ...

  5. SQL*Loader之CASE9

    CASE9 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase9.sql set termout off rem host write sys$output &quo ...

  6. SQL*Loader之CASE8

    CASE8 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase8.sql set termout off rem host write sys$output &quo ...

  7. SQL*Loader之CASE7

    CASE7 1. SQL脚本 case7包含两个SQL脚本,一个是删除脚本ulcase7e.sql,一个是创建脚本ulcase7s.sql [oracle@node3 ulcase]$ cat ulc ...

  8. SQL*Loader之CASE5

    CASE5 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase5.sql set termout off rem host write sys$output &quo ...

  9. SQL*Loader之CASE4

    CASE4 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase4.sql set termout off rem host write sys$output &quo ...

随机推荐

  1. loadRunner 负载机连接错误分析

    错误信息: Error: Process "lr_bridge.exe" was not created on remote host "192.168.86.17&qu ...

  2. selenium总结篇,常见方法和页面元素的操作【转】

    原文:http://www.cnblogs.com/tobecrazy/p/4570494.html 今天,总结一下selenium怎么操作web页面常见的元素. 主要有: 上传 alter dial ...

  3. Django如何搭建服务器

    建立django站点: 新建Django项目,我这里是使用命令创建项目的. django-admin startproject HelloDjango  创建HelloDjango项目 然后进入到He ...

  4. SQLSERVER全文搜索

    SQLSERVER全文搜索 看这篇文章之前请先看一下下面我摘抄的全文搜索的MSDN资料,基本上MSDN上关于全文搜索的资料的我都copy下来了 并且非常认真地阅读和试验了一次,并且补充了一些SQL语句 ...

  5. 基于ejbca构建独立ca系统

    ejbca,是一个CA(Certificate Authority)系统软件,CA是数字证书认证中心的简称,主要功能是管理数字证书,包括证书的颁发.销毁.更新等,ejbca实现了CA规范,因此可以用来 ...

  6. 可在广域网部署运行的QQ高仿版 -- GG叽叽V3.5,增加自拍头像功能、细节优化(源码)

    距离上次发版本(GG叽叽V3.4,增加系统设置.最近联系人.群功能)又有1个月了,在这个月内,由于空闲时间不是很多,所以,GG增加的主要功能只是拍照并设定其为自己头像.修改密码.删除好友.以及一些bu ...

  7. 压力测试工具ab使用

    ab全名是apache bench,是apache自带的一款压力测试工具.它通过创建多个线程来模拟并发,测试目标是基于URL的,因此不论是什么web服务器都可以支持. 使用ab非常简单,进入apach ...

  8. Java IO5:字符流

    字符流 字节流提供了处理任何类型输入/输出操作的功能(因为对于计算机而言,一切都是0和1,只需把数据以字节形式表示就够了),但它们不可以直接操作Unicode字符,因为上一篇文章写了,一个Unicod ...

  9. Silverlight中异步调用WCF服务,传入回调函数

    以前学的ASP.NET,调用的都是同步方法,同步方法的好处就是,一步一步走,完成这步才会走下一步.然而,WCF使用的都是异步方法,调用之后不管有没有获得结果就直接往下走,最可恶的是异步函数都是Void ...

  10. Programming Erlang 学习笔记(一)

    入门 启动Shell 在cmd中输入命令”erl”,百分号(%)表示一个注释的开始,从百分号开始到这行结束的所有文本都被看做是注释. 一个完整的命令需要以一个句点和一个回车结束. 退出erlang的命 ...