CASE10

1. SQL脚本

[oracle@node3 ulcase]$ cat ulcase10.sql

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

rem do all cleanup

drop table orders;
drop table customers;
drop type item_list_type;
drop type item_type;
drop type customer_type; rem Create an ORDER record that has a VARRAY for the items that comprise the
rem order and has a reference field to a record in the CUSTOMER table for
rem the customer placing the order. rem create customer type create type customer_type as object (
cust_no char(5),
name char(20),
addr char(20)
);
/ rem create object table for customer type create table customers of customer_type
(primary key (cust_no))
object id primary key; rem create type for order items create type item_type as object (
item varchar(50),
cnt number,
price number(7,2)
);
/ rem create varray type for order items create type item_list_type as varray (1000) of item_type;
/ rem create orders table with varray for items and ref to object table create table orders (
order_no char(5),
cust ref customer_type references customers,
item_list item_list_type
); exit;
/

2. 控制文件

[oracle@node3 ulcase]$ cat ulcase10.ctl

-- Copyright (c) 1991, 2004 Oracle.  All rights reserved.
-- NAME
-- ulcase10.ctl - SQL*Loader Case Study 10: Loading REF Fields and VARRAYs
--
-- DESCRIPTION
-- This case study demonstrates the following:
--
-- Loading a customer table that has a primary key as its OID and
-- stores order items in a VARRAY.
--
-- Loading an order table that has a reference to the customer table and
-- the order items in a VARRAY.
--
-- TO RUN THIS CASE STUDY:
-- 1. Before executing this control file, log in to SQL*Plus as
-- scott/tiger. Enter @ulcase10 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=ulcase1.ctl0 LOG=ulcase10.log
--
-- NOTES ABOUT THIS CONTROL FILE
-- cust_no and item_list_count are FILLER fields. The FILLER field is
-- assigned values from the data field to which it is mapped.
--
-- The cust field is created as a REF field.
--
-- item_list is stored in a VARRAY.
--
-- The second occurrence of item_list identifies the datatype of each
-- element of the VARRAY. Here, the datatype is COLUMN OBJECT.
--
-- The listing of item, cnt, price shows all attributes of the column
-- object that are loaded for the VARRAY. The list is enclosed in parentheses.
--
-- The data is contained in the control file and is preceded by the
-- BEGINDATA parameter.
--
LOAD DATA
INFILE *
CONTINUEIF THIS (1) = '*' INTO TABLE customers
REPLACE
FIELDS TERMINATED BY ","
(
cust_no CHAR,
name CHAR,
addr CHAR
) INTO TABLE orders
REPLACE
FIELDS TERMINATED BY ","
(
order_no CHAR,
cust_no FILLER CHAR,
cust REF (CONSTANT 'CUSTOMERS', cust_no),
item_list_count FILLER CHAR,
item_list VARRAY COUNT (item_list_count)
(
item_list COLUMN OBJECT
(
item CHAR,
cnt CHAR,
price CHAR
)
)
) BEGINDATA
*00001,Spacely Sprockets,15 Space Way,
*00101,00001,2,
*Sprocket clips, 10000, .01,
Sprocket cleaner, 10, 14.00
*00002,Cogswell Cogs,12 Cogswell Lane,
*00100,00002,4,
*one quarter inch cogs,1000,.02,
*one half inch cog, 150, .04,
*one inch cog, 75, .10,
Custom coffee mugs, 10, 2.50

执行后结果:

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

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

SQL> select * from customers;

CUST_ NAME           ADDR
----- -------------------- --------------------
00001 Spacely Sprockets 15 Space Way
00002 Cogswell Cogs 12 Cogswell Lane SQL> desc orders
Name Null? Type
----------------------------------------- -------- ----------------------------
ORDER_NO CHAR(5)
CUST REF OF CUSTOMER_TYPE
ITEM_LIST ITEM_LIST_TYPE SQL> select order_no from orders; ORDER
-----
00101
00100 SQL> select cust from orders; CUST
--------------------------------------------------------------------------------
00003C038A0038035D767AE692347EE050A8C00D0209980000001726010001000100290000000000
0C0100050100002A00078401FE0000000D053030303031 00003C038A0038035D767AE692347EE050A8C00D0209980000001726010001000100290000000000
0C0100050100002A00078401FE0000000D053030303032 SQL> select item_list from orders; ITEM_LIST(ITEM, CNT, PRICE)
--------------------------------------------------------------------------------
ITEM_LIST_TYPE(ITEM_TYPE('Sprocket clips', 10000, .01), ITEM_TYPE('Sprocket clea
ner', 10, 14)) ITEM_LIST_TYPE(ITEM_TYPE('one quarter inch cogs', 1000, .02), ITEM_TYPE('one hal
f inch cog', 150, .04), ITEM_TYPE('one inch cog', 75, .1), ITEM_TYPE('Custom cof
fee mugs', 10, 2.5))

查看日志文件:

[oracle@node3 ulcase]$ cat ulcase10.log

SQL*Loader: Release 11.2.0.1.0 - Production on Fri Sep 19 04:02:40 2014

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

Control File:   ulcase10.ctl
Data File: ulcase10.ctl
Bad File: ulcase10.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: 1:1 = 0X2a(character '*'), in current physical record
Path used: Conventional Table CUSTOMERS, loaded from every logical record.
Insert option in effect for this table: REPLACE Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
CUST_NO FIRST * , CHARACTER
NAME NEXT * , CHARACTER
ADDR NEXT * , CHARACTER Table ORDERS, loaded from every logical record.
Insert option in effect for this table: REPLACE Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
ORDER_NO NEXT * , CHARACTER
CUST_NO NEXT * , CHARACTER
(FILLER FIELD)
CUST DERIVED REF
Arguments are:
CONSTANT 'CUSTOMERS'
CUST_NO
ITEM_LIST_COUNT NEXT * , CHARACTER
(FILLER FIELD)
ITEM_LIST DERIVED * VARRAY
Count for VARRAY
ITEM_LIST_COUNT *** Fields in ITEM_LIST
ITEM_LIST DERIVED * COLUMN OBJECT *** Fields in ITEM_LIST.ITEM_LIST
ITEM FIRST * , CHARACTER
CNT NEXT * , CHARACTER
PRICE NEXT * , CHARACTER
*** End of fields in ITEM_LIST.ITEM_LIST *** End of fields in ITEM_LIST Table CUSTOMERS:
2 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. Table ORDERS:
2 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. Space allocated for bind array: 149120 bytes(64 rows)
Read buffer bytes: 1048576 Total logical records skipped: 0
Total logical records read: 2
Total logical records rejected: 0
Total logical records discarded: 0 Run began on Fri Sep 19 04:02:40 2014
Run ended on Fri Sep 19 04:02:41 2014 Elapsed time was: 00:00:01.33
CPU time was: 00:00:00.23

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

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

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

  5. SQL*Loader之CASE8

    CASE8 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase8.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. strncpy和memcpy的区别

    今天不小心在该用memcpy的时候,用了strncpy使自己吃了亏,所以写出这个博文. memcpy就是纯字节拷贝,而strncpy就不同了,字符串是以'\0'结尾的.如果一个字符buffer长度为6 ...

  2. vertica在电信的应用

    本文介绍了什么 ´ 电信级大数据分析典型需求 ´ Vertica数据库特点及与其他数据库对比 ´ Vertica核心技术介绍 ´ 基于Vertica的典型分系统架构简介 电信级大数据分析典型需求 ´  ...

  3. 安卓Notification的setLatestEventInfo is undefined出错不存在的解决

    用最新版的SDK,在做状态栏通知时,使用了Notification的setLatestEventInfo(),结果提示: The method setLatestEventInfo(Context, ...

  4. oracle ORA-12514: TNS: no listener 解决方案

    服务端:oracle 11g 客户端: pl/sql 问题描述: 用客户端 pl/sql 连接登录的时候,提示 "ORA-12514: TNS: no listener". 在服务 ...

  5. lxc on centos

    终于把lxc的网络配通了,也不知道对不对,记一下 一开始都是雷同的地方 yum install libcgroup lxc lxc-templates 安装lxc cgroup 然后记得 chkcon ...

  6. linux-12基本命令之 cat,more,head, tail ,tr,od,wc,cut,diff

    1.cat 命令 用于查看纯文本文件(较短),格式:"cat[选项][文件]" 查看文本文件 [root@localhost /]# cat 文件名 cat 参数 参数 作用 -n ...

  7. blogilo在chinaunix发布博客的设置

    1. 在日志类型菜单中选择"Metaweblog API". 2. 在日志的远程发布url中输入"http://blog.chinaunix.net/xmlrpc.php ...

  8. xtrabackup_binlog_pos_innodb 和 xtrabackup_binlog_info

    用过 xtrabackup 工具的 innobackupex 脚本备份数据的人可能会注意到,–apply-log 处理过的备份数据里有两个文件说明该备份数据对应的 binlog 的文件名和位置.但有时 ...

  9. Java构建工具Ant小记(一)

    Ant简介 Ant是基于java的构建工具.理论上来说它类似与make工具,但是却克服了make的一些固有的缺陷. 传统的Make是基于操作系统shell的构建工具,虽然也可以基于工作的os对make ...

  10. 【Bugly干货分享】手把手教你逆向分析 Android 程序

    很多人写文章,喜欢把什么行业现状啊,研究现状啊什么的写了一大通,感觉好像在写毕业论文似的,我这不废话,先直接上几个图,感受一下. 第一张图是在把代码注入到地图里面,启动首页的时候弹出个浮窗,下载网络的 ...