SQL*LOADER的应用和场景

本文详细介绍如何使用Oracle SQL*Loader工具将数据从文本文件加载到现有表中,包括创建表、数据文件、控制文件,以及通过SQL*Loader命令进行数据加载的过程。同时,文章还介绍了如何创建外部表并通过SQL*Loader生成控制文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Load data into an exsit table

1. login as scott

2. create table sql_loader_test
SQL> create table sql_loader_test
(first varchar2(10),
last varchar2(10));

Table created.

3. create data file sql_loader_test.txt in folder /home/scott
$ cat sql_loader_test.txt
John,Watson
Roopesh,Ramklass
Sam,Alapati

4. create control file sql_loader_test.ctl in folder /home/scott
$ cat sql_loader_test.ctl
load data
infile ‘sql_loader_test.txt’
badfile ‘sql_loader_test.bad’
truncate
into table sql_loader_test
fields terminated by ‘,’
trailing nullcols
(first,last)

5. using command sqlldr to load data from file
$ sqlldr ‘scott/tiger’ control=‘sql_loader_test.ctl’

SQL*Loader: Release 12.1.0.2.0 - Production on Mon Jan 28 11:42:09 2019

Copyright © 1982, 2014, Oracle and/or its affiliates. All rights reserved.

Path used: Conventional
Commit point reached - logical record count 4

Table SQL_LOADER_TEST:
3 Rows successfully loaded.

Check the log file:
sql_loader_test.log
for more information about the load.

6. checking the table sql_loader_test
SQL> select * from sql_loader_test;

FIRSTLAST
JohnWatson
RoopeshRamklass
SamAlapati

creating one external table via sqlldr

7. create the external table file for the exsiting one
$ sqlldr scott/tiger control=‘sql_loader_test.ctl’ external_table=generate_only
SQL*Loader: Release 12.1.0.2.0 - Production on Mon Jan 28 13:52:52 2019

Copyright © 1982, 2014, Oracle and/or its affiliates. All rights reserved.

Path used: External Table

8. create specific pysical data file path from oracle side (grant access with DBA first)

SQL> grant create any directory to scott;
SQL> create directory system_dmp as ‘/home/scott’;

9. modify the auto-generation file with the property paramters
$ cat sql_loader_test.log
SQL> CREATE TABLE sql_loader_test_ext
(
“FIRST” VARCHAR2(10),
“LAST” VARCHAR2(10)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYSTEM_DMP
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE ‘SYSTEM_DMP’:'sql_loader_test.bad’
LOGFILE 'sql_loader_test.log’
READSIZE 1048576
FIELDS TERMINATED BY “,” LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
“FIRST” CHAR(255)
TERMINATED BY “,”,
“LAST” CHAR(255)
TERMINATED BY “,”
)
)
location
(
‘sql_loader_test.txt’
)
)REJECT LIMIT UNLIMITED;

10. testing the table available
SQL> select * from sql_loader_test_ext;

FIRSTLAST
JohnWatson
RoopeshRamklass
SamAlapati
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值