SQL Loader没有插入数据

时间:2017-03-26 19:29:59

标签: sql-loader

我对使用SQL很陌生,所以如果这是一个简单的错误,我很抱歉。基本上我需要将一些数据加载到表中。但是,当我尝试使用sql loader将数据插入表中时,它不会被插入,但是没有错误表明出现了任何问题。

表:

create table Test(var char(3), var2 char(10), var3 number(7,2), 
var4 char(3),primary key (var));

这是我的控制文件(Test1.ctl):

LOAD DATA
INFILE *
REPLACE INTO TABLE Test
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY "'" TRAILING NULLCOLS
(var, var2, var3, var4 terminated by whitespace)
BEGINDATA
'123','test',12345,'321'
'321','test2',54321,null

我也尝试使用单独的.csv文件来加载数据而不是BEGINDATA,但两种方法都会发生同样的事情。

当我尝试加载数据时,从命令提示符开始,会发生这种情况:

[******** ~]$ sqlldr user_name Test1.ctl
Password:******

SQL*Loader: Release 10.2.0.3.0 - Production on Sun Mar 26 14:01:21 2017

[******** ~]$ 

然后当我去sqlplus检查表时,它是空的。

SQL> desc Test;
Name                                      Null?    Type
----------------------------------------- -------- -------------------------
VAR                                       NOT NULL CHAR(3)
VAR2                                               CHAR(10)
VAR3                                               NUMBER(7,2)
VAR4                                               CHAR(3)

SQL> select * from Test;

no rows selected

SQL> 

我无法弄清楚为什么它不会被加载到桌面上。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

版本10是一个非常古老的版本!

我无法在12c中重现您的问题。你应该加载一行;第二行失败,因为它试图加载字符串" null"这是CHAR(3)

中的4个字符
 sqlldr scott test1.ctl
Password:

SQL*Loader: Release 12.1.0.2.0 - Production on Mon Mar 27 10:04:06 2017

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

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

Table TEST:
  1 Row successfully loaded.

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


 cat test1.log

SQL*Loader: Release 12.1.0.2.0 - Production on Mon Mar 27 10:04:06 2017

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

Control File:   test1.ctl
Data File:      test1.ctl
  Bad File:     test1.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:    none specified
Path used:      Conventional

Table TEST, loaded from every logical record.
Insert option in effect for this table: REPLACE
TRAILING NULLCOLS option in effect

   Column Name                  Position   Len  Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
VAR                                 FIRST     *   ,  O(') CHARACTER            
VAR2                                 NEXT     *   ,  O(') CHARACTER            
VAR3                                 NEXT     *   ,  O(') CHARACTER            
VAR4                                 NEXT     *  WHT O(') CHARACTER            

Record 2: Rejected - Error on table TEST, column VAR4.
ORA-12899: value too large for column "SCOTT"."TEST"."VAR4" (actual: 4, maximum: 3)


Table TEST:
  1 Row successfully loaded.
  1 Row 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:                  66048 bytes(64 rows)
Read   buffer bytes: 1048576

Total logical records skipped:          0
Total logical records read:             2
Total logical records rejected:         1
Total logical records discarded:        0

Run began on Mon Mar 27 10:04:06 2017
Run ended on Mon Mar 27 10:04:08 2017

Elapsed time was:     00:00:02.68
CPU time was:         00:00:00.03