SQL*Loader之CASE8

CASE8

1. SQL脚本

[[email protected] 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. 控制文件

[[email protected] 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. 数据文件

[[email protected] 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  

执行后结果:

[[email protected] ulcase]$ sqlplus scott/tiger @ulcase8.sql

[[email protected] 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

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

查看日志文件:

[[email protected] 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
时间: 2024-10-30 22:58:04

SQL*Loader之CASE8的相关文章

SQL*loader实验

SQL*Loader 用法: sqlldr keyword=value [,keyword=value,... ] SQL*Loader通过控制文件实现对记录的处理,例子命令行下sqlldr scott/tiger control=case.ctl(并非数据库sql>下) case.ctl内容如下: load data infile *  ##使用*表示加载的数据在控制文件中,如果是独立文件要使用'绝对路径名' into table bonus  ##指定要将数据加载到哪个表中,该表必须已经存在

SQL*Loader FAQ

SQL*Loader FAQ: Contents [hide] 1 What is SQL*Loader and what is it used for? 2 How does one use the SQL*Loader utility? 3 How does one load MS-Excel data into Oracle? 4 Is there a SQL*Unloader to download data to a flat file? 5 Can one load variable

Oracle中的sql loader

oracle 的sql loader用来将操作系统上的数据文件中的内容加载到oracle数据库中. 要使用sql loader,需要先创建一个控制文件,里面告诉sql loader在启动了sql loader之后的加载数据的策略. 新建一个studentdataload.ctl文件,写入   load data      infile 'studentdata.txt'      into table studentinfo      fields terminated by '|'      

SQL LOADER 的用法 TXT文件导入非常之快

前提,需要本地安装ORACLE 客户端 控制文件 cms.ctl load dataCHARACTERSET UTF8infile 'oracle.txt'APPEND INTO TABLE JR fields terminated by '|'(BUKRS,LONNO,WAERS,BLDAT,BUDAT,SHKZG,DLCOD,HKONT,FPGRP,FPNAM,LONPR,WRBTR,ECNMA,DLNAM,EVTCD,SEVTC,SEVTD,CITYC,CITY,LONTP,PAYER,R

Oracle Sql Loader的学习使用

最近由于遇到oracle控制文件的使用,虽然不是很复杂,但是从来没有用过,专门花点时间看看.点击 这里 查看详细 1,概述: Sql Loader: 一个批量工具,将文件数据导入到数据库.可以导入一个表或者多个表,甚至可以在导入时修改数据. 2,使用 a,你电脑需要装Oracle,不然你是找不到Sqlldr 这个命令的. 在控制输入台输入 sqlldr: 会列出相关的参数介绍. > sqlldr . . . Usage: SQLLDR keyword=value [,keyword=value,

SQL*Loader数据装载工具入门_超越OCP精通Oracle视频课程培训24

oracle视频教程目标     Oracle视频教程,风哥本套oracle教程培训学习Oracle SQL*Loader概念及用法及SQL*Loader两个案例,同时课件带有近20个案例用于大家自行练习.适用人群IT相关从业人员.Oracle数据库技术人员.想加工资的.想升职的都可以. 视频在线学习地址:http://edu.51cto.com/course/course_id-6987.html Oracle视频教程简介本课程介绍:Oracle视频教程,风哥本套oracle教程培训学习Ora

[Oracle] SQL*Loader 详细使用教程(2)- 命令行参数

sqlldr工具 SQL*Loader的客户端工具是sqlldr,在操作系统的命令行下输入sqlldr,后面不接任何参数,将显示帮助信息如下所示(所有命令行参数的简单描述及其默认值),所以你并不需要对下面的参数死记硬背,当你忘记它们时,可以通过这个方式快速查询. [plain] view plain copy print? Valid Keywords: userid -- ORACLE username/password control -- control file name log -- 

[Oracle] SQL*Loader 详细使用教程(4)- 字段列表

在上一篇中我们介绍了SQL*Loader中最重要的文件——控制文件,而本篇要介绍控制文件中最重要的部分——字段列表,字段列表的作用是把数据文件中的记录和数据库中表的列对应起来,下面是字段列表的一个例子,本篇我们将一一讲解它们的意思. . . . 1 (hiredate SYSDATE, 2 deptno POSITION(1:2) INTEGER EXTERNAL(2) NULLIF deptno=BLANKS, 3 job POSITION(7:14) CHAR TERMINATED BY W

SQL*Loader之CASE1

最近项目涉及到将文本文件中的数据导入到Oracle数据库中,故研究了下SQL*Loader,官档提供的资料不是很丰富,很多案例中出现的语句在官档中找不到出处.但它提供的案例本身却彰显出了SQL*Loader功能的强大.鉴于Oracle 11g的软件本身没有携带这些案例,需要专门到官方网站下载Oracle Database 11g Release 2 Examples,甚是麻烦.在此,将这些案例分享,也方便以后研究.借鉴. 因官方文档还没有研究完,手里还有本<Oracle SQL*Loader: