gpt4 book ai didi

sql-server - 将平面文件导入 SQL - 添加字符后不会抛出错误

转载 作者:行者123 更新时间:2023-12-04 02:05:47 25 4
gpt4 key购买 nike

我正在开发一个将文本文件中的数据加载到 SQL Server 上的表中的程序包。

文本文件包含以下格式的数据

enter image description here

我在这里包括平面文件连接管理器 -

enter image description here

我已经创建了一个测试表

enter image description here

执行包并将数据移动到表中。

enter image description here

然后编辑其中一列以包含更多字符(在第二列中包含 s)

enter image description here

而不是包出错......它成功运行并将额外的字符移到下一列。

enter image description here

有人可以帮我吗?

最佳答案

为什么包没有抛出异常?

这是正常的,您正在阅读具有以下规范的固定宽度列(固定宽度或不规则右边)的平面文件源。

"Ragged Right", which is exactly the same as "Fixed Width", except that it gives you the option to insert a linefeed character (or CRLF, etc.) at the end of each line of data.

(您可以检查平面文件连接管理器以查看规范)

初始状态

数据:

0001aijn fkds jmcl wuj

规范和结果:

Col001: From 0 -> 3      '0001'
Col002: From 4 -> 7 'aijn'
Col003: From 8 -> 11 ' fkd'
Col004: From 12 -> 13 's '
Col005: From 14 -> 18 'jmcl '
Col006: From 19 -> end 'wuj'

第二状态

因此,当您添加 S 字符时,数据如下所示:

0001aijns fkds jmcl wuj

规范和结果:

Col001: From 0 -> 3      '0001'
Col002: From 4 -> 7 'aijn'
Col003: From 8 -> 11 's fk'
Col004: From 12 -> 13 'ds'
Col005: From 14 -> 18 ' jmcl'
Col006: From 19 -> end ' wuj'

更多信息:


是否有任何解决方法...在这种情况下它会在什么地方引发错误?

  1. 在平面文件连接管理器中使用定界格式
  2. 转到“高级”选项卡,删除除一列以外的所有列
  3. 将数据类型更改为 DT_WSTR 并将长度更改为 4000
  4. 在数据流任务中添加平面文件源、条件拆分、脚本组件、派生列转换、OLEDB 目标,如下图所示

enter image description here

  1. 使用条件拆分根据列的长度过滤行:

    LEN([Column0]) == 22

enter image description here

  1. 在脚本组件中编写以下代码(用于在行长度> 22 时引发错误):

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

    Throw New Exception("Length constraint violated")

    End Sub
  2. 指定以下派生列

enter image description here

  1. 将结果映射到 OLEDB Destination

关于sql-server - 将平面文件导入 SQL - 添加字符后不会抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48176868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com