数据流任务不从oracle db更新SQL Server表

时间:2014-09-26 18:24:26

标签: sql sql-server oracle ssis

我完全不熟悉使用MS Visual Studios和创建包。

据说,我创建了一个应该运行SQL任务编辑器的包(从Oracle数据库中提取数据),然后使用OLE DB连接的数据流任务来更新SQL Server上的表。

我的sql编辑器任务使用'变量'选项中的'sql,该变量包含在代码中的最后一个运行日期变量(变量LastRunDate应该查看SQL服务器表中的字段,以查找包的最后日期跑得很成功)。使用此日期,它应将此日期之后输入的Oracle数据库数据提取到SQL Server表中。 sql编辑器任务运行正常;但是,当调用数据流时,OLE DB Source会出错

  

[OLE DB Source [1]]错误:SSIS错误代码DTS_E_OLEDBERROR   发生OLE DB错误   错误代码:0x80040E14。 OLE DB记录可用   来源:“Microsoft OLE DB Provider for Oracle”Hresult:0x80040E14
  描述:“ORA-00923:找不到FROM关键字”。

我没有正确设置什么?

在SQL编辑器任务的SQL语句中:

declare @lastRunDate datetime, @lastRunDate_AsString varchar(30), 
        @sqlScript varchar(1000);

set @lastRunDate = (SELECT LastSuccessRunDate 
                    FROM dbo.LastSuccessRunDate 
                    WHERE PackageName = 'V_M_E')

set @lastRunDate_AsString = (SELECT 
                                convert(varchar(20), @lastRunDate, 101) + '
                              ' + substring(convert(varchar(20), @lastRunDate, 9), 13, 5) + substring(convert(varchar(30), @lastRunDate, 9), 25, 2)
currentdate_time)

set @sqlScript = 'SELECT ep.member_id AS MEMBER_ID,  ep.NAME_FIRST AS
                  NAME_FIRST, ep.NAME_LAST AS NAME_LAST, ep.ADDRESS1 AS ADDRESS1, 
                  ep.ADDRESS2 AS ADDRESS2, ep.ZIP AS ZIP, ep.CITY AS CITY, ep.STATE
                  AS STATE, to_date(ep.BIRTH_DATE, ''MM/DD/YYYY'') AS BIRTH_DATE, 
                  ep.GENDER AS GENDER,  '''' AS RACE ,  '''' AS "LANGUAGE",  
                  nc.NAME_FIRST  || '' '' || nc.NAME_LAST AS EMER_CONTACT,  ep.plan AS
                  "LOB", al.affiliation_secondary AS PLAN_DESC, to_date(ep.end_date,
                  ''MM/DD/YYYY'') AS EXP_COVERAGE_DATE, ''RECIPIENT''  AS "TYPE"  
                  FROM
                       scb.ep_view ep,   SCB.N_C NC,  scb.name,  scb.afflib al 
                  WHERE
                       al.affiliation_id = sc_base.name.text3 AND sc_base.name.name_id =
nc.name_id AND nc.name_id  = ep.name_id AND
(to_date(ep.addr_update_date,''mm/dd/yyyy'') > to_date(''' +
@lastRunDate_AsString + ''', ''mm/dd/yyyy hh:miam'') OR
to_date(ep.plan_update_date,''mm/dd/yyyy'') > to_date(''' +
@lastRunDate_AsString + ''', ''mm/dd/yyyy hh:miam'')) UNION SELECT
hf.member_id AS MEMBER_ID,  hf.NAME_FIRST AS NAME_FIRST,  hf.NAME_LAST
AS NAME_LAST,  hf.ADDRESS1 AS ADDRESS1,  hf.ADDRESS2 AS ADDRESS2, 
 hf.ZIP AS ZIP,  hf.CITY AS CITY,  hf.STATE AS STATE,
to_date(hf.BIRTH_DATE, ''MM/DD/YYYY'') AS BIRTH_DATE,  hf.GENDER AS
GENDER,  '''' AS RACE ,  '''' AS "LANGUAGE",   nc.NAME_FIRST  || '' ''
|| nc.NAME_LAST AS EMER_CONTACT,  hf.plan AS "LOB",
al.affiliation_secondary AS PLAN_DESC, TO_DATE(hf.end_date,
''MM/DD/YYYY'') AS EXP_COVERAGE_DATE, ''RECIPIENT''  AS "TYPE" FROM
scb.hf_view hf,   SCB.N_C NC,  scb.name,  scb.afflib al WHERE
al.affiliation_id = sc_base.name.text3 AND sc_base.name.name_id  =
nc.name_id AND nc.name_id  = hf.name_id AND
(to_date(hf.addr_update_date,''mm/dd/yyyy'') > to_date(''' +
 @lastRunDate_AsString + ''', ''mm/dd/yyyy hh:miam'') OR
to_date(hf.plan_update_date,''mm/dd/yyyy'')  >  to_date(''' +
@lastRunDate_AsString + ''', ''mm/dd/yyyy hh:miam''))'

select @sqlScript as SQLSU

2 个答案:

答案 0 :(得分:0)

你在动态sql中的第二个sql中缺少FROM子句。

这是因为当您动态创建sql语句时,您的文本将被截断为1000个字符。

而不是VARCHAR(1000)使用NVARCHAR(MAX)

答案 1 :(得分:0)

使用将超过1000个字符的字符串分配给@sqlScript varchar(1000)