我一直在使用sql*loader和to\u date()作为我的一个date类型字段

wqlqzqxt  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(448)

我使用一个sql*加载程序将表从db2加载到oracledb

LOAD DATA INFILE '<path><File_name>.del' 
replace
into table schema.tableName fields terminated by ','
(
col1,
col2,
col3,....
)
Rejected - Error on table schema_name.table_name, column col3.
ORA-01861: literal does not match format string.

由于col3是date类型,我们需要将其转换为oracle可接受的date格式。有人能告诉我如何使用sql加载器中的to_date()吗?

7gcisfzg

7gcisfzg1#

举个例子:
我的测试表,它将保存输入数据:

SQL> desc test
 Name                                      Null?    Type
 ----------------------------------------- -------- -------------------
 ID                                                 NUMBER
 DATUM                                              DATE

SQL>

控制文件;笔记 to_date 函数调用(双引号,正确的日期格式掩码,它必须与正在加载的数据格式相匹配)
第3行,格式为“无效”

load data 
infile *
replace
into table test
fields terminated by ','
trailing nullcols
( 
id,
datum "to_date(:datum, 'yyyy-dd-mm')"
)

begindata
1,2020-20-05
2,2020-28-12
3,20200215

加载会话:

SQL> alter session set nls_date_format = 'dd.mm.yyyy';

Session altered.

SQL> $sqlldr scott/tiger control=test20.ctl log=test20.log

SQL*Loader: Release 11.2.0.2.0 - Production on Sri Svi 20 08:10:53 2020

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

Commit point reached - logical record count 2
Commit point reached - logical record count 3

SQL> select * From test;

        ID DATUM
---------- ----------
         1 20.05.2020
         2 28.12.2020

SQL>

如您所见,第3行未加载。日志文件内容。注意 ORA-01861 错误:

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
------------------------------ ---------- ----- ---- ---- ---------------------
ID                                  FIRST     *   ,       CHARACTER            
DATUM                                NEXT     *   ,       CHARACTER            
    SQL string for column : "to_date(:datum, 'yyyy-dd-mm')"

Record 3: Rejected - Error on table TEST, column DATUM.
ORA-01861: literal does not match format string

Table TEST:
  2 Rows 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.

所以:确保所有输入数据遵循相同的格式掩码。

相关问题