简体   繁体   English

使用Spring JdbcTemplate中的调用来调用存储的函数

[英]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;
    /

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. 我已经用一个函数和一个过程制作了这个程序包,我正在尝试使用spring jdbctemplate从我的Java代码中调用它们。 But procedure is running fine but unable to call this function. 但是过程运行良好,但无法调用此函数。

int param1 =5 , param2 = 10;
jdbcTemplate.update( "call pk_sahil.squareNumDummy(?,?)",param1,param2);

this procedure is running fine. 此过程运行良好。

jdbcTemplate.update( "call pk_sahil.sumFun(?,?)",param1,param2);

upon running this function i'm getting below error 运行此功能后,我得到以下错误

console log of error 错误的控制台日志

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.update('call ...')方法调用该函数?

您可以从jdbcTemplate.queryForObject()调用存储的函数,如下所示:

int sum = jdbcTemplate.queryForObject("SELECT pk_sahil.squareNumDummy(?,?)", new Object[] {param1,param2});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM