当我在 Spring boot 应用程序中使用 JDBC 模板连接存储过程时,出现以下错误。仅获取 accIds 参数时出错
已解决[org.springframework.jdbc.UncategorizedSQLException:CallableStatementCallback; SQL 的未分类 SQLException [{call prc_Test( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; SQL状态[S0002]; e 错误代码[8169];从字符串转换为 uniqueidentifier 时转换失败。]
String aa= "aa95dc9c-0c75, b96bc70b-858e";
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate)
.withProcedureName("prc_Test");
Map<String, Object> inParamMap = new LinkedHashMap<String, Object>();
//inParamMap.put("accIds", lst.stream().collect(Collectors.joining(",")));
inParamMap.put("accIds", aa);
存储过程位于 Azure SQL 数据库中
CREATE PROCEDURE [dbo].[prc_Test]
@accIds varchar(max) = '',
@paSize int = 10,
@pagecount int =1,
@isOpenCases bit =1 ,
@comId VARCHAR(MAX)='#',
@casestatus VARCHAR(MAX)='#',
AS
BEGIN
.............................
FROM c_test2
WHERE accIds in (select cast(value as uniqueidentifier) from string_split (@accIds,',') )
AND (@comId = '#' OR [test_comp] IN (SELECT VALUE FROM string_split (@comId,',')))
....................................
.................................
.............................................
FROM c_test2
WHERE accIds in (select cast(value as uniqueidentifier) from string_split (@accIds,',') )
AND(@comId = '#' OR [test_comp] IN (SELECT VALUE FROM string_split (@comId,',')))
................................................
.......................................
order by test_data desc
OFFSET (@pagecount-1) * @pagesize ROWS
FETCH NEXT @pagesize ROWS ONLY
RETURN 0
END
..............................
知道为什么会出现错误吗?
Conversion failed when converting from a character string to uniqueidentifier.
提供的字符串:
String aa = "aa95dc9c-0c75, b96bc70b-858e";
不包含有效的唯一标识符号。这可能是导致上述错误的原因。您可以尝试使用下面的代码来调用具有有效唯一标识符的存储过程:
EXEC [dbo].[prc_Test]
@accIds = '3F2504E0-4F89-11D3-9A0C-0305E82C3301,3F2504E0-4F89-11D3-9A0C-0305E82C3302',
@paSize = 2,
@pagecount = 1,
@isOpenCases = 1,
@comId = 'CompanyA',
@casestatus = '#';
这将返回一个有效行,如下所示: