在 PLSQL 中我运行:
truncate table MyOracleTableName;
commit work;
insert into MyOracleTablename
select a,b,c,trunc(sysdate) as datadate
from AnotherOracleTableName
where there is a ton of nasty criteria
union
select a,b,c,trunc(sysdate) as datadate from AnotherOracleTableName
where there is a ton of different nasty criteria;
commit work;
在 PLSQL Developer 中,这会插入一行。 当我在 SSIS 中运行 SQL(没有分号和提交工作语句)时,我从 MyOracleTableName 得到一个主键冲突。
我已验证来自 SSIS 的截断已在 Oracle 中提交。
当我在 PLSQL Developer 中运行上述 SQL 并将并集替换为 union all 时,我看到第二行并且插入因 PK 违规而失败。正如它应该与一个联合一样,所有都允许重复。
这是目前使用 MSDAORA 的 SSIS 2005 包的一部分,它工作得很好。我现在正在使用 Oracle 的 native OLE DB 提供程序在 SSIS 2008 中重写。
我无法在我的新环境中使用 MSDAORA。这是一个驱动程序问题吗?除了将它们分解为多个语句(其中第二个语句仅插入 MyOracleTableName 中尚不存在的内容)之外,还有其他解决方法吗?
问候。
最佳答案
晚饭后我想通了这个问题。
主键约束是 A 列和 B 列上的复合键。Union 对 a、b、c 列和日期进行重复数据删除。在 Oracle 中,trunc(sysdate) 返回 mm/dd/yyyy。在 SSIS 中,trunc(sysdate) 被解析到秒或毫秒。由于时间戳,这会产生两个唯一的行(对于 SQL Server 和 Microsoft),然后尝试在 a、b 和 c 列重复的地方插入重复的行。
解决方案是这样的:
truncate table MyOracleTableName;
commit work;
insert into MyOracleTablename
select a.*,
trunc(sysdate) as datadate
from(
select a,b,c
from AnotherOracleTableName
where there is a ton of nasty criteria
union
select a,b,c from AnotherOracleTableName
where there is a ton of different nasty criteria) a
commit work;
这允许联合杀死重复项并运行 trunc(sysdate) 一次,从而将单行呈现给我的主键约束。
谢谢。
关于oracle - 为什么 Oracle 联盟会在 SSIS 中创建副本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12824784/