oracle - 使用 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。
解决方案
根据您到目前为止发布的内容,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>
推荐阅读
- java - 使用 OpenGL 和 LibGDX 生成体素土地的低 FPS
- python - 你如何在python的条件中使用“all()”?
- rust - 将当前目录中的所有文件内容读入向量
- powershell - 更改每个 PowerShell 会话的语言
- javascript - 使用 reduce 重新映射具有子数组的数组
- sum - 找到两个最小的整数,它们相加时小于 x 但相乘时大于 x
- javascript - 如何在函数范围内初始化变量并避免全局范围?
- c++ - 在 C++ 中禁用断言宏
- javascript - 调用异步请求时如何避免重复?
- swift - Swift 5.2 Xcode 11.4 Vapor 4.0.0 我应该如何在我的模型中编码 PK?