我有一个包含游标的SQL脚本,它遍历表的行以将该值用作存储过程参数的输入。 效果很好。
现在,我想使用RStudio从R执行此脚本。但是游标会在几行之后过早停止。
(使用'DBI'和'ODBC'程序包,Rstudio和SQL Server之间的连接已建立并正常工作。我能够运行'普通'查询)
知道为什么吗?
这是光标的脚本,用于从表中获取变量并使用不同的参数执行存储过程
DECLARE vendor_cursor CURSOR FOR
SELECT vessel_maintype, vessel_subtype, vessel_size, p_high_speed, p_medium_speed
FROM dynamic_cube_import_shipbuilding_verteilungen
OPEN vendor_cursor
FETCH NEXT FROM vendor_cursor
INTO @maintype , @subtype, @size, @p_high, @p_medium
WHILE @@FETCH_STATUS = 0
BEGIN
exec dynamic_high_speed_trend_shipbuilding_verteilungen @new_scenario_name = 'High-Speed trend for PSV 2-4000dwt+',
@vessel_maintype_clarkson =@maintype,
@vessel_subtype_clarkson= @subtype,
@vessel_size_clarkson= @size,
@p_high_speed = @p_high,
@p_medium_speed = @P_medium
FETCH NEXT FROM vendor_cursor
INTO @maintype, @subtype, @size, @p_high, @p_medium
END
CLOSE vendor_cursor;
DEALLOCATE vendor_cursor;