CASE8

1. SQL脚本

[oracle@node3 ulcase]$ cat ulcase8.sql

set termout off

rem host write sys$output "Building case 8 demonstration tables.  Please wait"

drop table lineitem;

create table lineitem
(l_orderkey number,
l_partkey number,
l_suppkey number,
l_linenumber number,
l_quantity number,
l_extendedprice number,
l_discount number,
l_tax number,
l_returnflag char,
l_linestatus char,
l_shipdate date,
l_commitdate date,
l_receiptdate date,
l_shipinstruct char(17),
l_shipmode char(7),
l_comment char(43))
partition by range (l_shipdate)
(
partition ship_q1 values less than (TO_DATE('01-APR-1996', 'DD-MON-YYYY')),
partition ship_q2 values less than (TO_DATE('01-JUL-1996', 'DD-MON-YYYY')),
partition ship_q3 values less than (TO_DATE('01-OCT-1996', 'DD-MON-YYYY')),
partition ship_q4 values less than (TO_DATE('01-JAN-1997', 'DD-MON-YYYY'))
); exit

2. 控制文件

[oracle@node3 ulcase]$ cat ulcase8.ctl

-- Copyright (c) 1991, 2004 Oracle.  All rights reserved.
-- NAME
-- ulcase8.ctl - SQL*Loader Case Study 8: Loading Partitioned Tables
--
-- DESCRIPTION
-- This case study demonstrates the following:
-- Partitioning of data.
--
-- Explicitly defined field positions and datatypes.
--
-- Loading data using the fixed-record-length option.
--
-- TO RUN THIS CASE STUDY:
-- 1. Before executing this control file, log in to SQL*Plus as
-- scott/tiger. Enter @ulcase8 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=ulcase8.ctl LOG=ulcase8.log
--
-- NOTES ABOUT THIS CONTROL FILE
-- This control file loads the lineitem table with fixed-length
-- records, partitioning the data according to shipment date.
--
-- The INFILE clause specifies that each record in the datafile is
-- of fixed length (129 bytes in this example).
--
-- The PARTITION clause identifies the column name and location of the
-- data in the datafile to be loaded into each column.
--
LOAD DATA
INFILE 'ulcase8.dat' "fix 129"
BADFILE 'ulcase8.bad'
TRUNCATE
INTO TABLE lineitem
PARTITION (ship_q1)
(l_orderkey position (1:6) char,
l_partkey position (7:11) char,
l_suppkey position (12:15) char,
l_linenumber position (16:16) char,
l_quantity position (17:18) char,
l_extendedprice position (19:26) char,
l_discount position (27:29) char,
l_tax position (30:32) char,
l_returnflag position (33:33) char,
l_linestatus position (34:34) char,
l_shipdate position (35:43) char,
l_commitdate position (44:52) char,
l_receiptdate position (53:61) char,
l_shipinstruct position (62:78) char,
l_shipmode position (79:85) char,
l_comment position (86:128) char)

3. 数据文件

[oracle@node3 ulcase]$ cat ulcase8.dat

     1 151978511724386.60 7.04.0NO09-SEP-6412-FEB-9622-MAR-96DELIVER IN PERSONTRUCK  iPBw4mMm7w7kQ zNPL i261OPP
1 2731 73223658958.28.09.06NO12-FEB-9628-FEB-9620-APR-96TAKE BACK RETURN MAIL 5wM04SNyl0AnghCP2nx lAi
1 3370 3713 810210.96 .1.02NO29-MAR-9605-MAR-9631-JAN-96TAKE BACK RETURN REG AIRSQC2C 5PNCy4mM
1 5214 46542831197.88.09.06NO21-APR-9630-MAR-9616-MAY-96NONE AIR Om0L65CSAwSj5k6k
1 6564 6763246897.92.07.02NO30-MAY-9607-FEB-9603-FEB-96DELIVER IN PERSONMAIL CB0SnyOL PQ32B70wB75k 6Aw10m0wh
1 7403 160524 31329.6 .1.04NO30-JUN-9614-MAR-9601 APR-96NONE FOB C2gOQj OB6RLk1BS15 igN
2 8819 82012441659.44 0.08NO05-AUG-9609-FEB-9711-MAR-97COLLECT COD AIR O52M70MRgRNnmm476mNm
3 9451 721230 41113.5.05.01AF05-SEP-9629-DEC-9318-FEB-94TAKE BACK RETURN FOB 6wQnO0Llg6y
3 9717 1834440788.44.07.03RF09-NOV-9623-DEC-9315-FEB-94TAKE BACK RETURN SHIP LhiA7wygz0k4g4zRhMLBAM
3 9844 1955 6 8066.64.04.01RF28-DEC-9615-DEC-9314-FEB-94TAKE BACK RETURN REG AIR6nmBmjQkgiCyzCQBkxPPOx5j4hB 0lRywgniP1297

执行后结果:

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

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

SQL> select L_ORDERKEY,L_PARTKEY,L_SHIPDATE from lineitem;

L_ORDERKEY L_PARTKEY  L_SHIPDAT
---------- ---------- ---------
1          1519       09-SEP-64
1          2731       12-FEB-96
1          3370       29-MAR-96

--因为列数太多,在这里我们只选取三列,可见只有三条记录被插入。

查看日志文件:

[oracle@node3 ulcase]$ cat ulcase8.log

SQL*Loader: Release 11.2.0.1.0 - Production on Fri Sep 19 03:30:54 2014

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

Control File:   ulcase8.ctl
Data File: ulcase8.dat
File processing option string: "fix 129"
Bad File: ulcase8.bad
Discard File: none specified (Allow all discards) Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional Table LINEITEM, partition SHIP_Q1, loaded from every logical record.
Insert option in effect for this partition: TRUNCATE Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
L_ORDERKEY 1:6 6 CHARACTER
L_PARTKEY 7:11 5 CHARACTER
L_SUPPKEY 12:15 4 CHARACTER
L_LINENUMBER 16:16 1 CHARACTER
L_QUANTITY 17:18 2 CHARACTER
L_EXTENDEDPRICE 19:26 8 CHARACTER
L_DISCOUNT 27:29 3 CHARACTER
L_TAX 30:32 3 CHARACTER
L_RETURNFLAG 33:33 1 CHARACTER
L_LINESTATUS 34:34 1 CHARACTER
L_SHIPDATE 35:43 9 CHARACTER
L_COMMITDATE 44:52 9 CHARACTER
L_RECEIPTDATE 53:61 9 CHARACTER
L_SHIPINSTRUCT 62:78 17 CHARACTER
L_SHIPMODE 79:85 7 CHARACTER
L_COMMENT 86:128 43 CHARACTER Record 4: Rejected - Error on table LINEITEM, partition SHIP_Q1.
ORA-14401: inserted partition key is outside specified partition Record 5: Rejected - Error on table LINEITEM, partition SHIP_Q1.
ORA-14401: inserted partition key is outside specified partition Record 6: Rejected - Error on table LINEITEM, partition SHIP_Q1.
ORA-14401: inserted partition key is outside specified partition Record 7: Rejected - Error on table LINEITEM, partition SHIP_Q1.
ORA-14401: inserted partition key is outside specified partition Record 8: Rejected - Error on table LINEITEM, partition SHIP_Q1.
ORA-14401: inserted partition key is outside specified partition Record 9: Rejected - Error on table LINEITEM, partition SHIP_Q1.
ORA-14401: inserted partition key is outside specified partition Record 10: Rejected - Error on table LINEITEM, partition SHIP_Q1.
ORA-14401: inserted partition key is outside specified partition Table LINEITEM, partition SHIP_Q1:
3 Rows successfully loaded.
7 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. Space allocated for bind array: 11008 bytes(64 rows)
Read buffer bytes: 1048576 Total logical records skipped: 0
Total logical records read: 10
Total logical records rejected: 7
Total logical records discarded: 0 Run began on Fri Sep 19 03:30:54 2014
Run ended on Fri Sep 19 03:30:54 2014 Elapsed time was: 00:00:00.31
CPU time was: 00:00:00.03

总结: 在本例中

1> PARTITION (ship_q1)子句表明只有符合这个分区范围内的值才能被插入,即l_shipdate小于01-APR-1996的数据可被插入。

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

  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之CASE7

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

  7. SQL*Loader之CASE6

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

  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. 查询Oracle锁表和解决方法

    Oracle数据库操作中,我们有时会用到锁表查询以及解锁和kill进程等操作,那么这些操作是怎么实现的呢?本文我们主要就介绍一下这部分内容.(1)锁表查询的代码有以下的形式:select count( ...

  2. Spring 3种注入方式

    spring的三种注入方式: 接口注入(不推荐) getter,setter方式注入(比较常用) 构造器注入(死的应用) 关于getter和setter方式的注入: autowire="de ...

  3. Entity Framework EF6使用 MySql创建数据库异常解决办法

    EF6使用MySQL数据库时,第一次创建数据库出现“Specified key was too long; max key length is 767 bytes”错误,解决办法请见以下连接. htt ...

  4. reduce() 函数

    reduce()函数 reduce()函数也是Python内置的一个高阶函数.reduce()函数接收的参数和 map()类似,一个函数 f,一个list,但行为和 map()不同,reduce()传 ...

  5. jmSlip WEB前端滑屏组件

    基于css3的滑屏组件 demo: http://slip.jm47.com 下载: https://github.com/jiamao/jmSlip 功能清单 区域横滚 整屏竖滚 滚动动画效果 区域 ...

  6. 【源码分享】WPF漂亮界面框架实现原理分析及源码分享

    1 源码下载 2 OSGi.NET插件应用架构概述 3 漂亮界面框架原理概述 4 漂亮界面框架实现  4.1 主程序  4.2 主程序与插件的通讯   4.2.1 主程序获取插件注册的服务   4.2 ...

  7. 【Bugly技术干货】那些年我们用过的显示性能指标

    Bugly 技术干货系列内容主要涉及移动开发方向,是由 Bugly 邀请腾讯内部各位技术大咖,通过日常工作经验的总结以及感悟撰写而成,内容均属原创,转载请标明出处. 前言: 注:Google 在自己文 ...

  8. C#中的线程三 (结合ProgressBar学习Control.BeginInvoke)

    C#中的线程三(结合ProgressBar学习Control.BeginInvoke) 本篇继上篇转载的关于Control.BeginInvoke的论述之后,再结合一个实例来说明Cotrol.Begi ...

  9. Linux4:useradd、userdel、passwd、groupadd、chgrp、chown、df、du、sort、wget

    useradd 添加新的用户账号,只有root账户可以操作 -d 目录:指定用户主目录(默认在home下),若此目录不存在可同时使用-m创建主目录 -g 用户组:指定用户所属的用户组 -G 用户组:指 ...

  10. hadoop研究:mapreduce研究前的准备工作

    继续研究hadoop,有童鞋问我,为啥不接着写hive的文章了,原因主要是时间不够,我对hive的研究基本结束,现在主要是hdfs和mapreduce,能写文章的时间也不多,只有周末才有时间写文章,所 ...