我需要从文本文件加载“日期”。我试过这样的
OPTIONS(skip=1)
load data
infile 'mypath\sample.txt'
APPEND
into table sample
fields terminated by "|"
TRAILING NULLCOLS
(
name CHAR(500) NULLIF (name=BLANKS)
, update_date date "MM/DD/RRRR HH:MI:SS" NULLIF (update_date=BLANKS)
)
我的系统日期格式为“6/21/2000 8:29:58 AM” 它没有在BAD文件中显示任何错误。但坏文件中有64条记录。请帮我。
感谢
答案 0 :(得分:1)
如果您发布一些示例输入行会更好;无论如何,使用下面的例子,它在我的情况下工作正常。看看,将其与您的尝试进行比较,进行更改(如果需要)。
首先,表格:
SQL> create table sample
2 (name varchar2(30),
3 update_date date);
Table created.
SQL>
控制文件(包括样本数据):
options (skip=1)
load data
infile *
replace
into table sample
fields terminated by '|' trailing nullcols
(
name,
update_date "to_date(:update_date, 'mm/dd/yyyy hh:mi:ss am')"
)
begindata
name | update_date
little | 6/21/2000 8:29:58 AM
foot | 12/21/2007 10:15:12 PM
加载会话:
M:\a1_maknuto>sqlldr little/foot@orcl control=test19.ctl log=test19.log
SQL*Loader: Release 11.2.0.2.0 - Production on Pon Sij 8 07:17:52 2018
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 1
Commit point reached - logical record count 2
M:\a1_maknuto>
结果:
SQL> select * from sample;
NAME UPDATE_DATE
------------------------------ -------------------
little 21.06.2000 08:29:58
foot 21.12.2007 22:15:12
SQL>
[编辑:如何减去12小时]
SQL> alter session set nls_date_format = 'mm/dd/yyyy hh:mi:ss am';
Session altered.
SQL> with test as
2 (select to_date('12/19/2017 12:49:48 PM', 'mm/dd/yyyy hh:mi:ss am') col
3 from dual
4 )
5 select
6 col,
7 col - 12/24 sub_12_hours
8 from test;
COL SUB_12_HOURS
---------------------- ----------------------
12/19/2017 12:49:48 PM 12/19/2017 12:49:48 AM
SQL>