我正在使用 sqlldr 加载一个文件,该文件的字段之一是数值。
问题在于,在某些记录中,数字有逗号,而在其他记录中,则没有。
所以做类似的事情
num "to_number(:num, '999,999,999.99')",
Run Code Online (Sandbox Code Playgroud)
用逗号加载记录,但不加载那些没有逗号的记录,并且正在做
num "to_number(:num)",
Run Code Online (Sandbox Code Playgroud)
只加载那些没有逗号的。
有没有办法告诉 Oracle (sqlldr) 逗号是可选的?
干得好:
SQL> desc loadertst;
Name Null? Type
----------------------------------------- -------- ----------------------------
COL1 NUMBER
SQL> !cat loadertst.ctl
load data
infile *
into table loadertst
fields terminated by ',' enclosed by '"'
(
col1 "to_number(replace(:col1,',',''))"
)
begindata
"123456"
"1,2,3,4,5,6"
SQL> !sqlldr phil/phil control=loadertst.ctl
SQL*Loader: Release 11.2.0.2.0 - Production on Thu Nov 29 23:33:17 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 2
SQL> select count(*) from loadertst;
COUNT(*)
----------
2
SQL>
Run Code Online (Sandbox Code Playgroud)
显然,您可能需要调整fields terminated by ',' enclosed by '"'
零件以适合您的数据。
归档时间: |
|
查看次数: |
16150 次 |
最近记录: |