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

前端 未结 5 1995
没有蜡笔的小新
没有蜡笔的小新 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:17

    There is a simple workaround for that restriction, which does not require a wrapper procedure, simply wrap the boolean parameter in PL/SQL in a CASE statement and use an Integer for binding:

    stmt = connection.prepareCall("begin" 
            +"  booleanFunc(par_bool => (CASE ? WHEN 1 THEN TRUE ELSE FALSE END)); "
            +"end;"
           );
    
    // now bind integer, 1 = true, 0 = false
    stmt.setInt(1, 0); // example for false
    

    You may wrap the Integer during bind the other way around, if your method uses boolean, for example:

    // now bind integer, 1 = true, 0 = false
    stmt.setInt(1, myBool ? 1 : 0); 
    

提交回复
热议问题