3

我正在尝试从命令行运行 SSIS 包,但我不断收到这个

“ORA-00907:缺少右括号”。

该包从 SSDT 运行良好,我使用的查询也是一个简单的查询。我确实尝试在运行时将值传递给查询。

变量声明:

在此处输入图像描述

我的查询使用表达式:

 "SELECT  country_id, city_id, name FROM cities where instr('" +  @[User::p_cityID]  + "' ||  ',', city_id || ',') > " +  @[User::p_count]

最终查询:(运行良好)

SELECT  country_id, city_id, name FROM cities where instr('DUBAI' ||  ',', city_id || ',') > 0

包调用:

Begin
declare @p_cityId varchar(10) = 'DUBAI'
declare @p_count varchar(10) = '0'

declare @query varchar(4000) = 
'"C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\DTExec.exe" /FILE C:\SSIS\pmtCity.dtsx /decrypt <mypass> /reporting V > C:\SSIS\log\citylog_'+
(replace(replace(replace(replace(convert(varchar(23), getdate(), 121),'-',''),':',''),' ',''),'.','')) +'.txt' 
+ ' /SET \Package.Variables[p_cityID].Value;''' +  @p_cityId + ''''
+ ' /SET \Package.Variables[p_count].Value;''' + @p_count + ''''

print @query
exec xp_cmdshell @query

End
4

1 回答 1

1

我认为您有单引号/双引号问题。尝试以下命令:

Begin
declare @p_cityId varchar(10) = 'DUBAI'
declare @p_count varchar(10) = '0'

declare @query varchar(4000) = 
'"C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\DTExec.exe" /FILE C:\SSIS\pmtCity.dtsx /decrypt <mypass> /reporting V > C:\SSIS\log\citylog_'+
(replace(replace(replace(replace(convert(varchar(23), getdate(), 121),'-',''),':',''),' ',''),'.','')) +'.txt' 
+ ' /SET \Package.Variables[p_cityID].Value;"' +  @p_cityId + '"'
+ ' /SET \Package.Variables[p_count].Value;"' + @p_count + '"'

print @query
exec xp_cmdshell @query

End

还可以尝试删除变量值周围的引号:

Begin
declare @p_cityId varchar(10) = 'DUBAI'
declare @p_count varchar(10) = '0'

declare @query varchar(4000) = 
'"C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\DTExec.exe" /FILE C:\SSIS\pmtCity.dtsx /decrypt <mypass> /reporting V > C:\SSIS\log\citylog_'+
(replace(replace(replace(replace(convert(varchar(23), getdate(), 121),'-',''),':',''),' ',''),'.','')) +'.txt' 
+ ' /SET \Package.Variables[p_cityID].Value;' +  @p_cityId 
+ ' /SET \Package.Variables[p_count].Value;' + @p_count 

print @query
exec xp_cmdshell @query

End
于 2019-06-04T13:45:22.040 回答