SQL Server BCP 不接受管道 |格式文件中的字段终止符

发布于 2024-10-30 22:27:26 字数 663 浏览 1 评论 0原文

我正在创建一个 BCP IN 进程来将管道分隔文件加载到表中。 BCP 实用程序向我提供错误 Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Syntax error at line 4 column 51 in xml format file运行。格式文件的第一行如下:

<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <RECORD>
        <FIELD ID="1" xsi:type="CharTerm" TERMINATOR="|", MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS" />

错误的位置就在“|”处。字段条目的。我尝试过单引号和双引号的各种变体,管道前面和周围没有引号和斜杠,但错误总是在同一位置抛出。

文件本身只是多行数据,在文件的顶部和底部带有管道分隔符和短标题/尾部记录。

I'm creating a BCP IN process to load a pipe delimited file into a table. The BCP utility gives me the error Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Syntax error at line 4 column 51 in xml format file when it runs. The first rows of the format file are as follows:

<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <RECORD>
        <FIELD ID="1" xsi:type="CharTerm" TERMINATOR="|", MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS" />

The location of the error is right at the "|" of the FIELD entry. I have tried various variations of single and double quotes, no quotes and slash in front of and around the pipe, but the error is always thrown at the same spot.

The file itself is just multiple rows of data with a pipe delimiter and short header/trailer records at the top and bottom of the file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

御弟哥哥 2024-11-06 22:27:26

不确定这是否是问题所在,但终止符属性后面的逗号看起来不正确

TERMINATOR="|",

Not sure if this is the issue but the comma after the terminator attribute doesn't look right

TERMINATOR="|",

孤独岁月 2024-11-06 22:27:26

我无法从问题中看出,但如果这与命令窗口、批处理文件和/或不那么微妙的平面文件操作有关,那么您可能会因为管道字符具有非常具体用途。在这些环境中,有许多晦涩的方法可以“转义”特殊字符......虽然我在战斗时从未找到任何可靠的文档,但随着时间的推移,我决定使用一个或一组引号,^,和&经常会解决我的问题。例如,您可以仔细尝试以下操作:

<FIELD ID="1" xsi:type="CharTerm" TERMINATOR="^|", MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS" />

<FIELD ID="1" xsi:type="CharTerm" TERMINATOR="&|", MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS" />

当然,这可能只是@Conrads逗号问题,在这种情况下忽略所有这些。

I can't tell from the question, but if this has something to do with Command windows, batch files, and/or not-so-subtle flat file manipulation, you may be being hit by the fact that the pipe character has a very specific use. There are a number of obscure ways to "escape" special characters in these environments... and while I never found any solid documentation back when I was fighting that fight, over time I determined that using one or a combination of quotes, ^, and & would often solve my problems. For example, you might carefully try the following:

<FIELD ID="1" xsi:type="CharTerm" TERMINATOR="^|", MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS" />

<FIELD ID="1" xsi:type="CharTerm" TERMINATOR="&|", MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS" />

Of course it might just be @Conrads comma problem, in which case ignore all this.

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