待导入列中的 SQLLDR 和 NULL 字段检测

发布于 2024-11-09 09:48:25 字数 868 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ双果 2024-11-16 09:48:25

它应该与以下子句一起使用:

WHEN TERMINATIONDATE = BLANKS

It should work with the following clause:

WHEN TERMINATIONDATE = BLANKS
表情可笑 2024-11-16 09:48:25

这不是最终的解决方案,并且有一些开销,但我可以在两次运行中完成:

a) 作为上面的 CTL 运行。
更改
当 TERMINATIONDATE = '' 时

当 TERMINATIONDATE != ''

丢弃的记录将被注入到 DISCARDFILE 'C:\temp\users.dsc'
现在我丢弃的文件将包含我想要上传的所有记录

b) 运行第二个 CTL 命令来拾取 DSC 文件作为输入,不要再跳过记录,也不要指定 when 子句 不是

LOAD DATA
INFILE 'C:\temp\users.dsc' 
BADFILE 'C:\temp\users.bad'
DISCARDFILE 'C:\temp\users-run2.dsc'
TRUNCATE
INTO TABLE "alawakaba"."users"
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
ID,
FIRSTNAME,
LASTNAME,
FUNCTION,
DEPARTMENT,
COSTCENTER,
HIREDATE,
Field8 FILLER,
TERMINATIONDATE,
LOCCODE
)

最好或最快的命令但这确实有效。

不敢相信如此简单的子句在 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

LOAD DATA
INFILE 'C:\temp\users.dsc' 
BADFILE 'C:\temp\users.bad'
DISCARDFILE 'C:\temp\users-run2.dsc'
TRUNCATE
INTO TABLE "alawakaba"."users"
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
ID,
FIRSTNAME,
LASTNAME,
FUNCTION,
DEPARTMENT,
COSTCENTER,
HIREDATE,
Field8 FILLER,
TERMINATIONDATE,
LOCCODE
)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文