一 描述
此档是sqlloader学习的第14篇.目的使用nullif子句判断加载入数据库的内容.
defaultif的使用在后面总结中也有说明,这里实验验证过程没有贴出,仅出结论.
二 操作环境
OS info
windows server 2003 32bit
DB info
连接到:Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
With the Partitioning option
JServer Release 9.0.1.1.1 - Production
SQL> set lines 150
SQL> COL PRODUCT FORMAT A55
SQL> COL VERSION FORMAT A15
SQL> COL STATUS FORMAT A15
SQL> SELECT * FROM PRODUCT_COMPONENT_VERSION;
PRODUCT VERSION STATUS
------------------------------------------------------- --------------- ---------------
NLSRTL 9.0.1.1.1 Production
Oracle9i Enterprise Edition 9.0.1.1.1 Production
PL/SQL 9.0.1.1.1 Production
TNS for 32-bit Windows: 9.0.1.1.0 Production
SQL>
other
脚本目录:C:\sqlloader_exec\ppt_case11三 过程设计
1.准备的flat源数据demo20.dat1 10
20lg
2.相关文件ppt_case11.sql
rem
rem
rem
set termout off
drop table tab_p11;
create table tab_p11 (col1 varchar2(10),col2 varchar2(10));
exit;
3.相关文件ppt_case10_p4.ctl
LOAD DATA
INFILE *
INTO TABLE tab_p11
TRUNCATE
(col1 position(1:2) integer external nullif n='1',
col2 position(3:8)
)
BEGINDATA
1 10
20lg
4.以scott用户登 录 数据库运行ppt_case11.sql初始化环境.
5.在cmd命令下执行sqlldr加载ppt_case11.ctl控制文件命令
6.查看sqlldr日志信息
7.查看sqlldr bad日志信息
8.查看数据库加载成功的数据
四 详细步骤操作
1.以scott用户登 录 数据库运行ppt_case11.sql初始化环境.C:\sqlloader_exec\ppt_case11>sqlplus "scott/tiger"
SQL*Plus: Release 9.0.1.0.1 - Production on 星期二 8月 7 20:15:55 2012
(c) Copyright 2001 Oracle Corporation. All rights reserved.
连接到:
Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
With the Partitioning option
JServer Release 9.0.1.1.1 - Production
SQL> @ppt_case11
从Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
With the Partitioning option
JServer Release 9.0.1.1.1 - Production中断开
C:\sqlloader_exec\ppt_case11>
2.在cmd命令下执行sqlldr加载ppt_case11.ctl控制文件命令
C:\sqlloader_exec\ppt_case11>sqlldr "scott/tiger" control=ppt_case11.ctl
SQL*Loader: Release 9.0.1.1.1 - Production on 星期二 8月 7 20:17:39 2012
(c) Copyright 2001 Oracle Corporation. All rights reserved.
达到提交点,逻辑记录计数2
C:\sqlloader_exec\ppt_case11>
3.查看sqlldr日志信息
SQL*Loader: Release 9.0.1.1.1 - Production on 星期二 8月 7 20:17:39 2012
(c) Copyright 2001 Oracle Corporation. All rights reserved.
控制文件: ppt_case11.ctl
数据文件: ppt_case11.ctl
错误文件: ppt_case11.bad
废弃文件: 未作指定
:
(可废弃所有记录)
加载数: ALL
跳过数: 0
允许的错误: 50
绑定数组: 64 行,最大 256000 字节
继续: 未作指定
所用路径: 常规
表TAB_P11
已加载从每个逻辑记录
插入选项对此表TRUNCATE生效
列名 位置 长度 中止 包装数据类型
------------------------------ ---------- ----- ---- ---- ---------------------
COL1 1:2 2 CHARACTER
NULL if COL1 =0X31(字符'1')
COL2 3:8 6 CHARACTER
表TAB_P11:
2 行加载成功
由于数据错误, 0 行没有加载。
由于所有 WHEN 子句失败, 0 行没有加载。
由于所有字段都为空的, 0 行没有加载。
为结合数组分配的空间: 768字节(64行)
读取 缓冲区字节数: 1048576
跳过的逻辑记录总数: 0
读取的逻辑记录总数: 2
拒绝的逻辑记录总数: 0
废弃的逻辑记录总数: 0
从星期二 8月 07 20:17:39 2012开始运行
在星期二 8月 07 20:17:40 2012处运行结束
经过时间为: 00: 00: 01.03
CPU 时间为: 00: 00: 00.00(可?
4.查看sqlldr bad日志信息
(无)
5.查看数据库加载成功的数据
C:\sqlloader_exec\ppt_case11>sqlplus "scott/tiger"
SQL*Plus: Release 9.0.1.0.1 - Production on 星期二 8月 7 20:18:52 2012
(c) Copyright 2001 Oracle Corporation. All rights reserved.
连接到:
Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
With the Partitioning option
JServer Release 9.0.1.1.1 - Production
SQL> select * from tab_p11;
COL1 COL2
---------- ----------
10
20 lg
SQL>
五 个人总结
1.此档使用 nullif 条件判断加载入数据库中的内容.因
... ...
(col1 position(1:2) integer external nullif n='1',
col2 position(3:8)
)
BEGINDATA
1 10
20lg
第一行position(1:2)内容满足nullif条件,所以第一行position(1:2)处向数据库表中载入null.
2.关于defaultif 数据库是如何加载数据的后面给出结论(实验过程略). 注: 以(.)的形式表示一个空格.
2.1 defaultif条件没有被用到的情况.
(col1 POSITION (1:5),
col2 POSITION (6:8) CHAR DEFAULTIF col1 = 'aname')
The datafile contains:
aname...
(注:此时数据库中载入 aname for col1 and NULL for col2.)
2.2 defaultif条件被使用到的情况
... ...
PRESERVE BLANKS
... ...
(col1 POSITION (1:5),
col2 POSITION (6:8) INTEGER EXTERNAL DEFAULTIF col1 = 'aname'
The datafile contains:
aname...
(注:此时数据库中载入aname for col1 and as 0 for col2.)
2.3 defaultif条件中使用position
(col1 POSITION (1:5),
col2 POSITION (6:8) INTEGER EXTERNAL DEFAULTIF (1:5) = BLANKS)
The datafile contains:
.....123
(注:此时数据库中载入 NULL for col1 and 0 for col2)
2.4 defaultif指定列名(估且叫做列吧,原文field name)
(col1 POSITION (1:5),
col2 POSITION(6:8) INTEGER EXTERNAL DEFAULTIF col1 = BLANKS)
The datafile contains:
.....123
(注:此时数据库中载入NULL for col1 and 123 for col2)
六 资料参考引用
http://afy.itpub.net/post/1128/22073
Oracle® Database Utilities
10g Release 2 (10.2)
Part Number B14215-01
9 Field List Reference
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11780477/viewspace-740304/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/11780477/viewspace-740304/