使用 SSIS 将数据从 Oracle 复制到 SQL Server 时处理时间戳/日期时间 [英] Dealing with Timestamp/Datetime when copying data from Oracle to SQL Server using SSIS
问题描述
我正在使用 SSIS 将数据从 Oracle 中的表复制到 SQL Server 2005 中的表中.不需要转换,所以它只是连接 OLE DB 源和 OLE DB 目标的直线.相当简单且有效,但在执行过程中,Oracle 表中的一条记录包含遇到的 0002 年的时间戳值,因此 SSIS 由于 oveflow 异常而出错.
I am using SSIS to copy data from a table in Oracle to a table in SQL Server 2005. There's no transformation required, so it's just a straight line connecting OLE DB Source to OLE DB Destination. Fairly simple and works, but during execution, a record in the Oracle table contains a timestamp value of the year 0002 in encountered, so SSIS errors out due to an oveflow exception.
如果我在 SQL Server 中创建一个额外的列,数据类型为字符串,然后重新映射,那么效果很好.但是,我更喜欢保留 Datatime 列并在我的目的地中使用它.我可以用 1900 或类似的东西替换 0002 年.那么在 SSIS 中实现 if-then-else 的最佳方法是什么?
If I create an extra column in SQL Server with the data type of string, and remap, then that works fine. However, I prefer to keep the Datatime column and use it in my destination. I am OK with replacing the year 0002 with something like 1900 or something like that. So what's the best way to achieve this if-then-else in SSIS?
推荐答案
我通常让 Oracle 在我的源查询中使用类似的东西来处理这个问题:
I usually let Oracle deal with that by using something like this in my source query:
CAST( Coalesce (
CASE
WHEN TO_CHAR(Effective_Date,'yyyy-mm-dd HH24:MI:SS') < '1900-01-01 00:00:00'
THEN TO_DATE('9999-12-31 00:00:00','yyyy-mm-dd HH24:MI:SS')
ELSE Effective_Date
END ,TO_DATE('9999-12-31 00:00:00','yyyy-mm-dd HH24:MI:SS')) AS DATE) AS Effective_Date
这设置了一个有效但非常未来的日期(由我签约的公司决定,作为必填日期字段中无效日期的表示.您也可以使用 '1900-01-01 00:00:00'
而不是 '9999-12-31 00:00:00'
) 在原始日期为 null
或小于 的情况下1900-01-01 00:00:00
.它还避免了 SSIS 对日期字段的后期处理.
This sets a valid but very future date (dictated by the company I am on contract to as the representation of an invalid date in a required date field. You could also use '1900-01-01 00:00:00'
instead of '9999-12-31 00:00:00'
) in cases where the original date is null
or less than 1900-01-01 00:00:00
. It also avoids post processing by SSIS on the date field.
这篇关于使用 SSIS 将数据从 Oracle 复制到 SQL Server 时处理时间戳/日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!