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. [转]Android开发:Parallax效果的ScrollerView,改编自ParallaxListView

    https://github.com/nirhart/ParallaxScroll这个gethub上的地址 本文转自http://www.2cto.com/kf/201502/376970.html ...

  2. 第52讲:Scala中路径依赖代码实战详解

    今天学习了scala中的路径依赖,来看一下实战代码 class Outer{  private val x = 10  class Inner{    private val y = x +10  } ...

  3. tableindex

    在写代码的时候,失焦的第一反应便是ng-blur,没想到在一个标签上其作用了,多加了几个标签没反应,于是发现了tableindex,写的代码列子如下,希望可以帮助你: <img src='{{a ...

  4. [置顶]PADS PCB功能使用技巧系列之NO.004- 如何做到20H规则?

    电源层与地层之间变化的电场在板边缘会向外辐射电磁干扰(EMI),称为边沿效应.20H规则可将70%的电场限制在接地层边沿内,100H可达到98%. (1)在Layout中,选择菜单栏Setup -&g ...

  5. JavaWeb的学习之Servlet(转载自孤傲苍狼)

    一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...

  6. ajax 跨域请求时url参数添加callback=?会实现跨域问题

    例如: 1.在 jQuery 中,可以通过使用JSONP 形式的回调函数来加载其他网域的JSON数据,如 "myurl?callback=?".jQuery 将自动替换 ? 为正确 ...

  7. 【IOS】异步调用--- 简单使用记录

    /×× ×实现功能:店铺被删除后,先显示提示toast.然后,页面休眠5秒后,再返回到店铺列表页面.×/ - (void)processDeleteShopError { _isLoadingData ...

  8. 回调函数(callback)

    参考维基百科链接: 中文:http://zh.wikipedia.org/wiki/%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0 英文:http://en.wikipedi ...

  9. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  10. nginx+winsw windows服务

    1.下载Nginx:http://nginx.org/en/download.html 2.下载winsw配置包:http://files.cnblogs.com/files/objecttozero ...