如何在 Erlang 中使用 odbc:param_query 调用存储过程获取数组 [英] How to call stored procedure taking array using odbc:param_query in Erlang
本文介绍了如何在 Erlang 中使用 odbc:param_query 调用存储过程获取数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 db2 中有一个存储过程
I have a stored procedure in db2
create type intArray as integer array[100]@
create or replace procedure sum(in numList intArray, out total integer)
begin
declare i, n integer;
set n = CARDINALITY(numList);
set i = 1;
set total = 100;
while (i <= n) do
set total = total + numList[i];
set i = i + 1;
end while;
end@
我正在尝试通过 Erlang odbc:param_query 调用.
I am trying to call through Erlang odbc:param_query.
odbc:param_query(Ref, "CALL sum (?, ?)", [{sql_integer,[1]}, {sql_integer,out, [1]}]).
以上内容给了我适当的回报
The above is giving me proper return as
{executed,1,[{101}]}
但是当我传递多个值时
odbc:param_query(Ref, "CALL sum (?, ?)", [{sql_integer,[1,2,3,4]}, {sql_integer,out, [1]}]).
抛出异常
异常退出:{badarg,odbc,param_query,'Params'}在函数 odbc:decode/1 中(odbc.erl,第 894 行)
exception exit: {badarg,odbc,param_query,'Params'} in function odbc:decode/1 (odbc.erl, line 894)
有没有其他方法可以将列表(数组)传递给存储过程?
Is there any other way to pass a list (Array) to the stored procedure?
推荐答案
我相信你需要在两个参数列表中包含相同数量的参数,这意味着在你的第二个列表或参数中添加三个 1.
I believe you need to have an equal amount of arguments in both lists of arguments, meaning add three 1s in your 2nd list or arguments.
odbc:param_query(Ref, "CALL sum (?, ?)", [{sql_integer, [1,2,3,4]}, {sql_integer, out, [1,1,1,1]}]).
这篇关于如何在 Erlang 中使用 odbc:param_query 调用存储过程获取数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文