2
    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. 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?

Sahil Kumar
  • 39
  • 1
  • 3
  • 9
  • 1
    Possible duplicate of [Spring JDBC Template for calling Stored Procedures](http://stackoverflow.com/questions/9361538/spring-jdbc-template-for-calling-stored-procedures) – Floern May 09 '17 at 08:36

1 Answers1

3

You can call a stored function from jdbcTemplate.queryForObject() as follows:

int sum = jdbcTemplate.queryForObject("SELECT pk_sahil.squareNumDummy(?,?)", new Object[] {param1,param2});
Robert
  • 5,278
  • 43
  • 65
  • 115
Ismail
  • 46
  • 2