在Java中调用oracle PL/SQL函数-无效的列类型错误 [英] calling oracle PL/SQL function in java - Invalid column type error
本文介绍了在Java中调用oracle PL/SQL函数-无效的列类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从java类中调用plsql函数,但是该函数(isValidPeriod)返回布尔数据类型,而JDBC不支持
I want to call a plsql function from java class but that function (isValidPeriod) return a boolean datat type and JDBC doesn't support it
推荐答案
对此限制有一个简单的解决方法,它不需要包装函数,只需将布尔函数本身包装在CASE
语句中并使用Integer用于绑定:
There is a simple workaround for that restriction, which does not require a wrapper function, simply wrap the boolean function itself in a CASE
statement and use an Integer for binding:
stmt = conn.prepareCall(
"BEGIN"
+ " ? := CASE WHEN (myBooleanFuncInOracle()) "
+ " THEN 1 "
+ " ELSE 0"
+ " END;"
+ "END;");
stmt.registerOutParameter(1, Types.INTEGER);
// exec
stmt.execute();
// get boolean from Integer
boolean myBool = (stmt.getInt(1) == 1);
如果您不能或不想更改函数,甚至不能创建包装函数,即在旧数据库中,则非常有用.
Very useful if you can't or don't want to change your function or even can't create a wrapper function, i.e. in legacy DBs.
这篇关于在Java中调用oracle PL/SQL函数-无效的列类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文