SQL*Loader之CASE4
CASE4
1. SQL脚本
[oracle@node3 ulcase]$ cat ulcase4.sql
set termout off rem host write sys$output "Building case 4 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 ulcase4.ctl
-- NAME
-- ulcase4.ctl - SQL*Loader Case Study 4: Loading Combined Physical Records
--
-- DESCRIPTION
-- This case study demonstrates the following:
-- Combining multiple physical records to form one logical
-- record with CONTINUEIF.
--
-- Inserting negative numbers.
--
-- Using REPLACE to indicate that the table should be emptied
-- before the new data is inserted.
--
-- Specifying a discard file in the control file using DISCARDFILE.
--
-- Specifying a maximum number of discards using DISCARDMAX.
--
-- Rejecting records due to duplicate values in a unique index
-- or due to invalid data values.
--
-- TO RUN THIS CASE STUDY:
-- 1. Before executing this control file, log in to SQL*Plus as
-- scott/tiger. Enter @ulcase4 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=ulcase4.ctl LOG=ulcase4.log
--
-- NOTES ABOUT THIS CONTROL FILE
-- DISCARDFILE specifies a discard file named ulcase4.dsc.
--
-- DISCARDMAX specifies a maximum of 999 discards allowed before
-- terminating the run. For all practical purposes, this allows
-- all discards for this test case. In real-world situations,
-- there may well be more than 999 discarded records.
--
-- REPLACE specifies that if there is data in the table being loaded,
-- then SQL*Loader should delete that data before loading new data.
--
-- CONTINUEIF specifies that if an asterisk is found in column 1
-- of the current record, then the next physical record after that
-- record should be appended to it from the logical record. Note that
-- column 1 in each physical record should then contain either an
-- asterisk or a nondata value.
--
-- The data file (ulcase4.dat) for this case study shows asterisks
-- in the first position and, though not visible, a newline character
-- is in position 20. Note that clark's commission is -10, and
-- SQL*Loader loads the value, converting it to a negative number.
--
-- The resulting log file will show that the last two records are
-- rejected, given two assumptions. If a unique index is created on
-- column empno, then the record for chin will be rejected because
-- his empno is identical to chan's. If empno is defined as NOT NULL,
-- then chen's record will be rejected because it has no value for
-- empno. --
LOAD DATA
INFILE "ulcase4.dat"
DISCARDFILE "ulcase4.dsc"
DISCARDMAX 999
REPLACE
CONTINUEIF (1) = '*'
INTO TABLE EMP ( EMPNO POSITION(01:04) INTEGER EXTERNAL,
ENAME POSITION(06:15) CHAR,
JOB POSITION(17:25) CHAR,
MGR POSITION(27:30) INTEGER EXTERNAL,
SAL POSITION(32:39) DECIMAL EXTERNAL,
COMM POSITION(41:48) DECIMAL EXTERNAL,
DEPTNO POSITION(50:51) INTEGER EXTERNAL,
HIREDATE POSITION(52:60) INTEGER EXTERNAL)
3. 数据文件
[oracle@node3 ulcase]$ cat ulcase4.dat
*7782 CLARK MA
NAGER 7839 2572.50 -10 2512-NOV-85
*7839 KING PR
ESIDENT 5500.00 2505-APR-83
*7934 MILLER CL
ERK 7782 920.00 2508-MAY-80
*7566 JONES MA
NAGER 7839 3123.75 2517-JUL-85
*7499 ALLEN SA
LESMAN 7698 1600.00 300.00 25 3-JUN-84
*7654 MARTIN SA
LESMAN 7698 1312.50 1400.00 2521-DEC-85
*7658 CHAN AN
ALYST 7566 3450.00 2516-FEB-84
* CHEN AN
ALYST 7566 3450.00 2516-FEB-84
*7658 CHIN AN
ALYST 7566 3450.00 2516-FEB-84
执行后结果:
[oracle@node3 ulcase]$ sqlplus scott/tiger @ulcase4.sql
[oracle@node3 ulcase]$ sqlldr userid=scott/tiger control=ulcase4.ctl
SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ------ --------- ----- --------- ------- ----- ------
7782 CLARK MANAGER 7839 12-NOV-85 2573 -10 25 7839 KING PRESIDENT 05-APR-83 5500 25 7934 MILLER CLERK 7782 08-MAY-80 920 25 7566 JONES MANAGER 7839 17-JUL-85 3124 25 7499 ALLEN SALESMAN 7698 03-JUN-84 1600 300 25 7654 MARTIN SALESMAN 7698 21-DEC-85 1313 1400 25 7658 CHAN ANALYST 7566 16-FEB-84 3450 25 7 rows selected.
不难发现,数据文件中有9条数据,但是最后插入的只有7条数据。执行sqlldr时,如果没有显性指定日志文件名,则会隐性创建一个同名日志,后缀为.log。
我们不妨来看看日志文件的记录
[oracle@node3 ulcase]$ cat ulcase4.log
SQL*Loader: Release 11.2.0.1.0 - Production on Thu Sep 18 23:41:36 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Control File: ulcase4.ctl
Data File: ulcase4.dat
Bad File: ulcase4.bad
Discard File: ulcase4.dsc
(Allow 999 discards) Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: 1:1 = 0X2a(character '*'), in current physical record
Path used: Conventional 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
SAL 32:39 8 CHARACTER
COMM 41:48 8 CHARACTER
DEPTNO 50:51 2 CHARACTER
HIREDATE 52:60 9 CHARACTER Record 8: Rejected - Error on table EMP, column EMPNO.
ORA-01400: cannot insert NULL into ("SCOTT"."EMP"."EMPNO") Record 9: Rejected - Error on table EMP.
ORA-00001: unique constraint (SCOTT.EMPIX) violated Table EMP:
7 Rows successfully loaded.
2 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: 4608 bytes(64 rows)
Read buffer bytes: 1048576 Total logical records skipped: 0
Total logical records read: 9
Total logical records rejected: 2
Total logical records discarded: 0 Run began on Thu Sep 18 23:41:36 2014
Run ended on Thu Sep 18 23:41:36 2014 Elapsed time was: 00:00:00.29
CPU time was: 00:00:00.07
可见,第8行记录因违法empno的非空约束,第9行记录因违反唯一索引而抛弃。
抛弃的两条记录可在控制文件指定的DISCARDFILE "ulcase4.dsc"中找到
[oracle@node3 ulcase]$ cat ulcase4.bad
* CHEN AN
ALYST 3450.00 -FEB-
* CHIN AN
ALYST 3450.00 -FEB-
总结:在本例中,
1> 指定了discard file,discardmax指定丢弃到该文件的记录最多为999条。
2> The REPLACE option executes a SQL DELETE FROM TABLE statement. All rows in the table are deleted and the new data is loaded. The REPLACE method is a table replacement, not a replacement of individual rows. SQL*Loader does not update existing records, even if they have null columns. --replace会删除所有数据,而不会更新既存的数据。
SQL*Loader之CASE4的更多相关文章
- SQL*LOADER错误总结
在使用SQL*LOADER装载数据时,由于平面文件的多样化和数据格式问题总会遇到形形色色的一些小问题,下面是工作中累积.整理记录的遇到的一些形形色色错误.希望能对大家有些用处.(今天突然看到自己以前整 ...
- Bulkcopy对应的实现是Oracle的SQL*LOADER,期间造成Index Unusable,并且last_ddl_time上是不体现的
部分项目反馈系统整体突然变慢,经查询发现一个系统核心的大数据表的索引状态全部是Unusable. 导致索引失效的直接原因:当某些操作导致数据的rowid改变,索引就会完全失效. 那什么时候会导致row ...
- SQL*Loader之CASE11
CASE11 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase11.sql set termout off rem host write sys$output &q ...
- SQL*Loader之CASE10
CASE10 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase10.sql rem host write sys$output "Building dem ...
- SQL*Loader之CASE9
CASE9 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase9.sql set termout off rem host write sys$output &quo ...
- SQL*Loader之CASE8
CASE8 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase8.sql set termout off rem host write sys$output &quo ...
- SQL*Loader之CASE7
CASE7 1. SQL脚本 case7包含两个SQL脚本,一个是删除脚本ulcase7e.sql,一个是创建脚本ulcase7s.sql [oracle@node3 ulcase]$ cat ulc ...
- SQL*Loader之CASE6
CASE6 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase6.sql set termout off rem host write sys$output &quo ...
- SQL*Loader之CASE5
CASE5 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase5.sql set termout off rem host write sys$output &quo ...
随机推荐
- No operation was found with the name {http://impl.service.xq.com/}sayHi
org.apache.cxf.common.i18n.UncheckedException: No operation was found with the name {http://impl.ser ...
- oracle数据库常用查询
一.数据库信息 1.数据库时间 select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') AS dbtime from dual; 2.主机OS类型 SELEC ...
- printf(""); 输出小题目
#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h> int main(){ int i=43; printf("%d\n&q ...
- 微小企业中Sqlserver2000服务器的日常备份与恢复
1:把数据库和备份分别放在二个硬盘上 2:不要相信用户会使用客户端坚持备份数据,比较靠谱的方法是为数据库建立维护计划 3:数据库采用每天完全备份,并且时间一定要选择在用户肯定开机的时候,因为很多用户晚 ...
- 解压缩c#
protected void btn_ServerClick(object sender, EventArgs e) { string strtxtPath = "E:/ ...
- 避开WebForm天坑,拥抱ASP.Net MVC吧
有鹏友在如鹏网的QQ群中提了一个问题: 请问,在ASP.Net中如何隐藏一个MenuItem,我想根据不同的权限,对功能菜单进行隐藏,用style不行. 如果要仅仅解答这个问题,很好解答,答案很简单: ...
- vc编译 curl 7.36.0
CURL邮件列表中提到官方最新版本的windows devel包中缺少文件,而我又用不到https,所以我就自己下载源码包来编译了 下载源码包:http://curl.haxx.se/download ...
- Blend 2015 教程 (三) 模板
前一篇讲述了一些基本样式的修改方法,并搭建了Style层的基本框架,本篇将进一步修改ListBox的样式. 1. 首先选中ListBox控件,在美工板导航栏中点击ListBox,选择 编辑其他模板-编 ...
- 继续SecureString
上回写了关于SecureString的特征和为什么我们要使用它,这篇继续研究研究这个SecureString. **主要内容:** - SecureString与String之间的转换 - Secur ...
- 分享最新的博客到LinkedIn Timeline
使用Octopress作为我的博客框架有两年了.使用起来一直很顺手,这个工具真正的把博客跟写代码等同起来,非常酷炫.再加上各种各样的定制化,简直是随心所欲.我针对自己的需求对Octopress框架进行 ...