我試圖通過存儲過程從SQL Server運行基本R腳本。我正在返回一個數據集,也想返回/輸出一個變量,但我無法做到這一點。如何從SQL Server運行R時返回變量
下面是存儲過程我有
DROP PROC IF EXISTS get_iris_dataset;
go
CREATE PROC get_iris_dataset
AS
BEGIN
declare @OutName float
EXEC sp_execute_external_script
@language = N'R'
, @script = N'
iris_data <- iris
out = 5.1;'
, @input_data_1 = N''
, @output_data_1_name = N'iris_data'
,@params= N'@out float OUTPUT'
,@out = @OutName OUTPUT
WITH RESULT SETS (("Sepal.Length" float not null,
"Sepal.Width" float not null,
"Petal.Length" float not null,
"Petal.Width" float not null, "Species" varchar(100)));
END;
return 0
go
我打電話如下步驟:
declare @OutputVar float
exec @OutputVar = get_iris_dataset
print @OutputVar
它確實輸出的數據集,但我不能夠存儲的值OutputVar中。
即使不輸出數據集,我也不能返回OutputVar的值,只嘗試捕獲OutputVar的值。 任何幫助表示讚賞。
在此先感謝!
我這裏看不到任何R代碼裏面。 –
R代碼只有2行。 iris_data < - iris, out = 5.1; –