SQLLoader7(只导入数据文件的其中几行记录)

时间:2022-03-24 04:24:25

数据文件:

D:\oracletest\test1.txt
1 SMITH CLERK 7902 1980-12-17 800 0 20
2 ALLEN SALESMAN 7698 1981-02-20 1600 300 30
3 WARD SALESMAN 7698 1981-02-22 1250 500 30
4 JONES MANAGER 7839 1981-04-02 2975 0 20
5 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30
6 BLAKE MANAGER 7839 1981-05-01 2850 0 30
7 CLARK MANAGER 7839 1981-06-09 2450 0 10
8 SCOTT ANALYST 7566 1987-04-19 3000 0 20
9 KING PRESIDENT 1111 1981-11-17 5000 0 10
10 TURNER SALESMAN 7698 1981-09-08 1500 0 30
11 ADAMS CLERK 7788 1987-05-23 1100 0 20
12 JAMES CLERK 7698 1981-12-03 950 0 30
13 FORD ANALYST 7566 1981-12-03 3000 0 20
14 MILLER CLERK 7782 1982-01-23 1300 0 10

控制文件:

D:\oracletest\testSqlLdr3.ctl
LOAD DATA
INFILE 'D:\oracletest\test1.txt'
BADFILE 'D:\oracletest\testSqlLdr3.bad'
DISCARDFILE 'D:\oracletest\testSqlLdr3.dsc'
REPLACE
INTO TABLE emp2
FIELDS TERMINATED BY WHITESPACE
(EMPNO,ENAME,JOB,MGR,HIREDATE DATE "YYYY-MM-DD",SAL,COMM,DEPTNO)

导入方式:
以下测试的数据导入,使用的控制文件都是同一个。
1、从第5行开始导入 skip=4,使用skip参数跳过前边4行。
执行命令时加上参数:skip=N,即导入第N+1行后的所有文件。

D:\oracletest>sqlldr scott/tiger@orcl control=D:\oracletest\testSqlLdr3.ctl skip=4

SQL*Loader: Release 11.2.0.1.0 - Production on 星期一 12月 1 00:08:03 2014

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

达到提交点 - 逻辑记录计数 9
达到提交点 - 逻辑记录计数 10

查看导入结果:

SQL> select * from emp2;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
5 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30
6 BLAKE MANAGER 7839 1981-05-01 2850 0 30
7 CLARK MANAGER 7839 1981-06-09 2450 0 10
8 SCOTT ANALYST 7566 1987-04-19 3000 0 20
9 KING PRESIDENT 1111 1981-11-17 5000 0 10
10 TURNER SALESMAN 7698 1981-09-08 1500 0 30
11 ADAMS CLERK 7788 1987-05-23 1100 0 20
12 JAMES CLERK 7698 1981-12-03 950 0 30
13 FORD ANALYST 7566 1981-12-03 3000 0 20
14 MILLER CLERK 7782 1982-01-23 1300 0 10 已选择10行。

2、只导入其中的第3行至第10行记录
即:SKIP=2 LOAD=10---LOAD指定要导入的数据行数。

D:\oracletest>sqlldr scott/tiger@orcl control=D:\oracletest\testSqlLdr3.ctl skip=4 load=10

SQL*Loader: Release 11.2.0.1.0 - Production on 星期一 12月 1 00:09:46 2014

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

达到提交点 - 逻辑记录计数 9
达到提交点 - 逻辑记录计数 10

查看导入结果:

SQL> select * from emp2;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
5 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30
6 BLAKE MANAGER 7839 1981-05-01 2850 0 30
7 CLARK MANAGER 7839 1981-06-09 2450 0 10
8 SCOTT ANALYST 7566 1987-04-19 3000 0 20
9 KING PRESIDENT 1111 1981-11-17 5000 0 10
10 TURNER SALESMAN 7698 1981-09-08 1500 0 30
11 ADAMS CLERK 7788 1987-05-23 1100 0 20
12 JAMES CLERK 7698 1981-12-03 950 0 30
13 FORD ANALYST 7566 1981-12-03 3000 0 20
14 MILLER CLERK 7782 1982-01-23 1300 0 10 已选择10行。

3、前3行和最后2行不导入
相当于只导入从第4行至总行数减2行之间的数据,skip=2,load=9

D:\oracletest>sqlldr scott/tiger@orcl control=D:\oracletest\testSqlLdr3.ctl skip=4 load=9

SQL*Loader: Release 11.2.0.1.0 - Production on 星期一 12月 1 00:14:09 2014

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

达到提交点 - 逻辑记录计数 9

查看导入结果:

SQL> select * from emp2;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
5 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30
6 BLAKE MANAGER 7839 1981-05-01 2850 0 30
7 CLARK MANAGER 7839 1981-06-09 2450 0 10
8 SCOTT ANALYST 7566 1987-04-19 3000 0 20
9 KING PRESIDENT 1111 1981-11-17 5000 0 10
10 TURNER SALESMAN 7698 1981-09-08 1500 0 30
11 ADAMS CLERK 7788 1987-05-23 1100 0 20
12 JAMES CLERK 7698 1981-12-03 950 0 30
13 FORD ANALYST 7566 1981-12-03 3000 0 20 已选择9行。