首页 > 解决方案 > 使用 oracle 的 sql loader 加载数据时忽略列值中的空格

问题描述

我正在尝试使用 oracle sql loader 加载数据并使用空格作为列的分隔符,但我面临的问题是其中一个列值包括空格,我需要您的支持以避免将此空间视为列分隔符。

我尝试使用 regexp_replace 和替换函数

DSTCOUNTRY " REGEXP_REPLACE(:DSTCOUNTRY,'dstcountry=','')",

列值为:dstcountry="United States"

并且要存储在表中的期望值为: United States

sql 加载器命令是:将数据 infile 'in' 附加到表 test_table 字段中,以“”结尾,可选地用 '"' 括起来 TRAILING NULLCOLS DSTCOUNTRY " REPLACE(:DSTCOUNTRY,'dstcountry=','')",

我正在使用 oracle 10G 和 12C。

标签: oraclesql-loader

解决方案


根据您到目前为止发布的内容,optionally enclosed您正在寻找它。这是一个例子。

测试表:

SQL> create table test (id number, dstcountry varchar2(20));

Table created.

控制文件(也包含样本数据):

load data 
infile *
replace
into table test
fields terminated by " " 
optionally enclosed by '"'
trailing nullcols
(
id,
dstcountry)

begindata
123 "Croatia"
125 "United States"

加载会话和结果:

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

SQL*Loader: Release 11.2.0.2.0 - Production on Pon Srp 22 17:59:23 2019

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

SQL> select * from test;

        ID DSTCOUNTRY
---------- --------------------
       123 Croatia
       125 United States

SQL>

推荐阅读