sqlldr 换行符 数据跨多行

APPLIES TO:

Oracle Database - Enterprise Edition - Version 19.3.0.0.0 and later
Information in this document applies to any platform.

GOAL

Given this control file:

load data
infile '<FileName>' "str x'0D'"
into table <TableName>
replace
fields terminated by "|"
trailing nullcols
(<Column1>,
<Column2>,
<Column3> char(4000)
)

and these 2 rows of data (the first marked in green and the 2nd in blue):

23|654|this data is normal
1|22|radom
data    spead between
lines

     (Notice:  The 2nd row spans multiple lines.)

SQL*Loader (sqlldr) loads the first row only and includes the ID of the second row at the end of it.

How can this data be successfully loaded?
 

SOLUTION

1.  Add a delimiter at the end of each row (as opposed to line) of data.  For instance, if the pipe "|" is used as a delimiter:

23|654|this data is normal|
1|22|radom
data    spead between
lines|

2.  Modify the str value in the control file to match the delimiter specified.  For example, to get the appropriate value for the pipe "|" as a delimiter, enter:

SQL> select utl_raw.cast_to_raw( '|'||chr(10) ) from dual;

UTL_RAW.CAST_TO_RAW('|'||CHR(10))
-------------------------------------------------------------------------------
7C0A

Note:  On Windows, you would use UTL_RAW.CAST_TO_RAW( '|'||chr(13)||chr(10) ).

     So the control file would be:

load data
infile '<FileName>' "str X'7C0A'"
into table <TableName>
replace
fields terminated by "|"
trailing nullcols
(<Column1>,
<Column2>,
<Column3> char(4000)
)


 


Use of the STR Attribute:

This is perhaps the most flexible method of loading data with embedded newlines. Using the STR attribute, we can specify a new end-of-line character (or sequence of characters). This allows us to create an input data file that has some special character at the end of each line the newline is no longer special.

Use a sequence of characters, typically some special marker, and then a newline. This makes it easy to see the end-of-line character when viewing the input data in a text editor or some utility, as each record still has a newline at the end of it. The STR attribute is specified in hexadecimal as shown above.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值