为什么Oracle Union在SSIS中创建副本?

时间:2012-10-10 17:13:41

标签: oracle ssis union

在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替换union时,我看到第二行并且插入失败了PK违规。因为它应该使用一个允许复制的联合。

这是目前使用MSDAORA的SSIS 2005软件包的一部分,它可以正常工作。我现在正在使用Native OLE DB providor for Oracle重新编写SSIS 2008。

我无法在新环境中使用MSDAORA。这是一个驱动程序问题,除了将这些问题分解为多个语句之外还有一个解决方法,其中第二个只插入MyOracleTableName中尚未包含的内容吗?

问候。

1 个答案:

答案 0 :(得分:0)

晚饭后我发现了问题。

主键约束是列A和B上的复合键。联盟对列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)一次,从而将单行呈现给我的主键约束。

谢谢。