待导入列中的 SQLLDR 和 NULL 字段检测
SQLLDR 和 CTL 文件
获取了要导入的 CSV 文件。
我想在我的 CTL 文件中指定仅当 CSV 文件中的某个列中有空值时才插入到我的表中。 EG 我只想上传没有终止日期的用户记录。
我尝试过各种选项
- When TERMINATIONDATE = ''
- When TERMINATIONDATE = ""
- When TERMINATIONDATE = null
- When TERMINATIONDATE = 'null'
它仅在我使用
- When TERMINATIONDATE != '' 时 有效 然后我得到了所有已被解雇的员工。 但我想要相反的......
看起来这毕竟是不可能的吗?
我的 CTL 文件
OPTIONS (SKIP=1)
LOAD DATA
INFILE 'C:\temp\users.csv'
BADFILE 'C:\temp\users.bad'
DISCARDFILE 'C:\temp\users.dsc'
TRUNCATE
INTO TABLE "alawakaba"."users"
When TERMINATIONDATE = ''
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
ID,
FIRSTNAME,
LASTNAME,
FUNCTION,
DEPARTMENT,
COSTCENTER,
HIREDATE,
Field8 FILLER,
TERMINATIONDATE,
LOCCODE
)
(Column8 只是我不需要的文件,所以我跳过它)
SQLLDR and CTL file
Got a CSV file to import.
I want to specify in my CTL file to insert only into my table when I've got an empty value in a certain column in my CSV file. E.G I want to upload only user's records who don't have a termination date.
I've tried various options
- When TERMINATIONDATE = ''
- When TERMINATIONDATE = ""
- When TERMINATIONDATE = null
- When TERMINATIONDATE = 'null'
It only works when I'm using
- When TERMINATIONDATE != ''
then i get all my employees that have been terminated.
But i want the opposite...
Doesn't look like it's possible after all?
my CTL file
OPTIONS (SKIP=1)
LOAD DATA
INFILE 'C:\temp\users.csv'
BADFILE 'C:\temp\users.bad'
DISCARDFILE 'C:\temp\users.dsc'
TRUNCATE
INTO TABLE "alawakaba"."users"
When TERMINATIONDATE = ''
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
ID,
FIRSTNAME,
LASTNAME,
FUNCTION,
DEPARTMENT,
COSTCENTER,
HIREDATE,
Field8 FILLER,
TERMINATIONDATE,
LOCCODE
)
(Column8 is just one I don't need so I'm skipping that)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它应该与以下子句一起使用:
It should work with the following clause:
这不是最终的解决方案,并且有一些开销,但我可以在两次运行中完成:
a) 作为上面的 CTL 运行。
更改
当 TERMINATIONDATE = '' 时
到
当 TERMINATIONDATE != ''
丢弃的记录将被注入到 DISCARDFILE 'C:\temp\users.dsc'
现在我丢弃的文件将包含我想要上传的所有记录
b) 运行第二个 CTL 命令来拾取 DSC 文件作为输入,不要再跳过记录,也不要指定 when 子句 不是
最好或最快的命令但这确实有效。
不敢相信如此简单的子句在 SQLLDR 中从一开始就不起作用。
It's not the ultimate solution and has some overhead but I can do it in 2 runs:
a) Run as CTL above.
Change the
When TERMINATIONDATE = ''
to
When TERMINATIONDATE != ''
The discarded records will be injected into the DISCARDFILE 'C:\temp\users.dsc'
now my discarded file will contain all the records i wanted to upload
b) Run a second CTL command to pickup the DSC file as input, don't skip records anymore and don't specify the when clause neither
Not the best or quickest one around but it does the trick.
Can't believe that such a simple clause is not working from the start in SQLLDR.