SQL 加载程序中的评论,CSV 文件

Comments in SQL Loader, CSV file

我正在生成一个 CSV 文件,该文件将使用 sqlldr 读入数据库,想知道是否有兼容的注释可以放入文件中?

# Currently I am using comments of this format
# and I want to add some information about where the file came from

但是,sqlldr 将这些报告为 rows not loaded due to data errors,这可能会使任何试图调试导入过程的用户感到困惑。

我看过 sqlldr documentation and it does not mention anything about comments. The answer to this question 还概述了 CSV 文件没有自己标准的注释,但标准是由读取文件的应用程序定义的(在这种情况下 sqlldr).

是否有可以与 sqlldr 一起使用的兼容评论类型?

我不认为 sqlldr 允许在数据中添加注释,但您可以通过在控制文件中指定一个 with 子句来绕过它,该子句只加载第一个行字符不等于 '#'。请注意 '#' 必须始终位于同一位置,而不是在线的任何位置。

编辑:我刚试过,效果很好。

数据文件:

# This is a comment in the data file
1|\a\ab\|do not "clean" needles|@
# This is a comment in the data file
2|\b\bg\|wall "69" side to end|@
# This is a comment in the data file

控制文件:

load data
infile 'x_test.dat'
into table X_TEST
when (1:1) <> '#'
fields terminated by "|" OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
  col1,
  col2,
  col3
)