SQL*Loader之CASE3

CASE3

1. SQL文件

[[email protected] ulcase]$ cat ulcase3.sql

set termout off

rem Do not clean up table because this example shows appending to existing
rem rows in table that also has new columns.

rem host write sys$output "Adding columns to emp.  Please wait."

alter table emp add (projno number, loadseq number);

exit
                                    

2. 控制文件

[[email protected] ulcase]$ cat ulcase3.ctl

-- NAME
-- ulcase3.ctl - SQL*Loader Case Study 3: Loading a Delimited,
-- Free-format File
--
-- DESCRIPTION
-- This case study demonstrates the following:
-- Loading data (enclosed and terminated) in stream format.
--
-- Loading dates using the DATE datatype.
--
-- Using SEQUENCE numbers to generate unique keys for loaded data.
--
-- Using APPEND to indicate that the table need not be empty before
-- inserting new records.
--
-- Using comments in the control file set off by two hyphens.
--
-- NOTES ABOUT THIS CONTROL FILE
-- This control file loads the same table as in case 2, but it
-- loads three additional columns (hiredate, projno, and loadseq).
-- The projno and loadseq columns are added to the emp table when
-- you run the ulcase3.sql script.
--
-- INFILE * specifies that the data is found at the end of the
-- control file.
--
-- APPEND specifies that the data can be loaded even if the table
-- already contains rows. That is, the table need not be empty.
--
-- The default terminator for the data fields is a comma, and some
-- fields may be enclosed by double quotation marks (").
--
-- The data to be loaded into column hiredate appears in the format
-- DD-Month-YYYY. The length of the date field is specified to have
-- a maximum of 20. The maximum length is in bytes, with default
-- byte-length semantics. If character-length semantics were used
-- instead, the length would be in characters. If a length is not
-- specified, then the length depends on the length of the date mask.
--
-- The SEQUENCE function generates a unique value in the column loadseq.
-- This function finds the current maximum value in column loadseq and
-- adds the increment (1) to it to obtain the value for loadseq for
-- each row inserted.
--
-- BEGINDATA specifies the end of the control information and the
-- beginning of the data.
--
-- Although each physical record equals one logical record, the fields
-- vary in length, so that some records are longer than others. Note
-- also that several rows have null values for comm.

LOAD DATA
INFILE *
APPEND

INTO TABLE EMP
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY ‘"‘
(empno, ename, job, mgr,
 hiredate DATE(20) "DD-Month-YYYY",
 sal, comm,
 deptno   CHAR TERMINATED BY ‘:‘,
 projno,
 loadseq  SEQUENCE(MAX,1) )

BEGINDATA
7782, "Clark", "Manager", 7839, 09-June-1981, 2572.50,, 10:101
7839, "King", "President", , 17-November-1981, 5500.00,, 10:102
7934, "Miller", "Clerk", 7782, 23-January-1982, 920.00,, 10:102
7566, "Jones", "Manager", 7839, 02-April-1981, 3123.75,, 20:101
7499, "Allen", "Salesman", 7698, 20-February-1981, 1600.00, 300.00, 30:103
7654, "Martin", "Salesman", 7698, 28-September-1981, 1312.50, 1400.00, 30:103
7658, "Chan", "Analyst", 7566, 03-May-1982, 3450,, 20:101
                                       

执行后结果:

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

[[email protected] ulcase]$ sqlldr userid=scott/tiger control=ulcase3.ctl

SQL> select * from emp;

EMPNO ENAME  JOB         MGR    HIREDATE       SAL     COMM   DEPTNO PROJNO    LOADSEQ
----- ------ ---------  -----   ---------      ------- -----  ------ ------ ----------
 7782 Clark  Manager     7839   09-JUN-81      2573            10    101        1

 7839 King   President          17-NOV-81      5500            10    102        2

 7934 Miller Clerk       7782   23-JAN-82       920            10    102        3

 7566 Jones  Manager     7839   02-APR-81      3124            20    101        4 

 7499 Allen  Salesman    7698   20-FEB-81      1600       300  30    103        5

 7654 Martin Salesman    7698   28-SEP-81      1313      1400  30    103        6

 7658 Chan   Analyst     7566   03-MAY-82      3450            20    101        7

7 rows selected.
时间: 2024-11-05 19:30:21

SQL*Loader之CASE3的相关文章

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: