在Spring JdbcTemplate中使用call调用存储的函数 [英] Calling stored function using call in Spring JdbcTemplate
问题描述
CREATE OR REPLACE PACKAGE BODY pk_sahil AS
procedure squareNumDummy(x in number,y in number) is
begin
dbms_output.put_line(x*y);
insert into sahil values('package',111);
end squareNumDummy;
function sumFun( x in number , y in number ) return number is
begin
insert into sahil values('function',222);
return x+y;
end sumFun;
END pk_sahil;
/
create or replace package pk_sahil as
procedure squareNumDummy(x in number, y in number);
function sumFun(x in number, y in number ) return number;
end pk_sahil;
/
我已经用一个函数和一个过程制作了这个程序包,我正在尝试使用spring jdbctemplate从我的Java代码中调用它们.但是过程运行正常,但无法调用此函数.
I've made this package with a function and a procedure in it and i'm trying to call them from my java code using spring jdbctemplate. But procedure is running fine but unable to call this function.
int param1 =5 , param2 = 10;
jdbcTemplate.update( "call pk_sahil.squareNumDummy(?,?)",param1,param2);
此过程运行正常.
jdbcTemplate.update( "call pk_sahil.sumFun(?,?)",param1,param2);
运行此功能后,我将遇到错误
upon running this function i'm getting below error
请纠正我是否不是以正确的方式调用该函数,还是需要处理函数的返回变量?如何从jdbctemplate.update('call ...')方法调用该函数?
Please correct me whether i'm not calling that function right way or i need to handle the return variable from function? How can i call that function from jdbctemplate.update(' call... ') method?
推荐答案
您可以从jdbcTemplate.queryForObject()
调用存储的函数,如下所示:
You can call a stored function from jdbcTemplate.queryForObject()
as follows:
int sum = jdbcTemplate.queryForObject("SELECT pk_sahil.squareNumDummy(?,?)", new Object[] {param1,param2});
这篇关于在Spring JdbcTemplate中使用call调用存储的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!