我已经在RTVS Visual Studio 2017中使用R创建了一个存储过程,在将它发布到我的数据库之后,当我尝试执行它时,我会得到这个错误:
Msg 39004,16级,20级,4号线 在使用HRESULT0x80004004执行“sp_execute_external_script”时发生了“R”脚本错误。 Msg 39019,16级,状态1,4号线 发生外部脚本错误:库中的错误(RODBC):没有名为“RODBC”调用的包:源-> withVisible -> eval -> ->库 ScaleR中的错误。有关更多信息,请查看输出。ScaleR中的错误(expr,in,ScaleR):错误。有关更多信息,请查看输出。调用:源-> withVisible -> eval -> -> .Call执行停止 Msg 11536、级别16、状态1、过程SqlSProc、第4批开始行2> EXECUTE语句失败,因为它的WITH结果集子句指定了1个结果集,但语句在运行时只发送了0个结果集。
这是我的SqlSProc.R代码:
library(RODBC)
channel <- odbcDriverConnect(settings$dbConnection1)
InputDataSet <- sqlQuery(channel, iconv(paste(readLines('c:/users/abdal/source/repos/correlation/correlation/sqlsproc.query.sql', encoding = 'UTF-8', warn = FALSE), collapse = '\n'), from = 'UTF-8', to = 'ASCII', sub = ''))
odbcClose(channel)
InputDataSet$OtherLangDescription <- as.factor(InputDataSet$OtherLangDescription)
orderList <- unique(InputDataSet$OtherLangDescription)
ListId <- lapply(orderList, function(x) subset(InputDataSet, OtherLangDescription == x)$WHWorkOrderHeaderId)
Initial_Tab <- lapply(ListId, function(x) subset(InputDataSet, WHWorkOrderHeaderId %in% x)$OtherLangDescription)
Correlation_Tab <- mapply(function(Product, ID) table(Product) / length(ID),
Initial_Tab, ListId)
colnames(Correlation_Tab) <- orderList
cor_per <- round(Correlation_Tab * 100, 2)
OutputDataSet <- data.frame(row = rownames(cor_per)[row(cor_per)], col = colnames(cor_per)[col(cor_per)], corr = c(cor_per))
OutputDataSet <- InputDataSetSQL查询检索R存储过程的数据:
SELECT
WHWorkOrderHeaderId, OtherLangDescription
FROM
Warehouse.WHWorkOrderDetails
INNER JOIN
Warehouse.WHWorkOrderHeader AS WHH ON Warehouse.WHWorkOrderDetails.WHWorkOrderHeaderId = WHH.ID
INNER JOIN
Warehouse.StockItems ON Warehouse.WHWorkOrderDetails.StockItemId = Warehouse.StockItems.Id
ORDER BY OtherLangDescription ASCSQL PROC模板:
CREATE PROCEDURE [SqlSProc]
AS
BEGIN
EXEC sp_execute_external_script @language = N'R'
, @script = N'_RCODE_'
, @input_data_1 = N'_INPUT_QUERY_'
--- Edit this line to handle the output data frame.
WITH RESULT SETS (([product_1] Nvarchar(MAX),[Product_2] Nvarchar(Max),[Correlation] INT));
END ; 发布于 2017-12-17 10:12:26
您的错误消息
库中的错误(RODBC):没有名为“RODBC”的包
指向缺少的包,必须在使用该包之前安装:
install.packages("RODBC")
library(RODBC)
[Rest of your R-code]以下错误很可能绑定到丢失的包中。有一个预期的结果集,但是SP返回时没有结果.
https://stackoverflow.com/questions/47853757
复制相似问题