Calling an Oracle PL/SQL procedure in Java using a CallableStatement with a boolean IN parameter gives an PLS-00306 oracle error:

前端 未结 5 1997
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 17:59

I have a pl/sql procedure on an Oracle 11g that has the following parameters:

PROCEDURE validate_product
   ( product_id_in IN varchar2 , 
     username_in in va         


        
5条回答
  •  清酒与你
    2021-02-19 18:19

    Starting with Oracle 12.2 there is a JDBC Support for Binding PLSQL_BOOLEAN

    I'll demonstrate is on a simple procedure with INand OUT BOOLEAN parameters

    create or replace PROCEDURE proc_C (flag_in BOOLEAN, flag_out OUT BOOLEAN) as
    begin
      flag_out := flag_in;
    end;
    /
    

    Unfortunately it is not possible to use directly setBoolean to bind the first parameter.

    The driver Version 19.3.0.0.0 returns in this case PLS-00306: wrong number or types of arguments in call to 'PROC_C'

    The workaround is simple using setObject(1,true,oracle.jdbc.OracleTypes.PLSQL_BOOLEAN)

    The whole example

    stmt = con.prepareCall("{ call proc_C(?,?)}") 
    stmt.setObject(1,false,oracle.jdbc.OracleTypes.PLSQL_BOOLEAN)
    stmt.registerOutParameter(2, oracle.jdbc.OracleTypes.PLSQL_BOOLEAN) 
    stmt.execute()
    flag = stmt.getBoolean(2)
    

提交回复
热议问题