I am trying to call an Oracle function from my Java code something like this :
Java
CallableStatement cstmt = p_con.prepareCall("{? = CALL FXRATE_ENTITY(?, ?, ?, ?, ?)}");
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setString(2, "SCR");
cstmt.setString(3,l_srccur);
cstmt.setString(4, l_tfcurr);
cstmt.setString(5, "B001");
cstmt.execute();
String res = cstmt.getString(1);
but i am getting an exception
java.sql.SQLException: Missing IN or OUT parameter at index:: 6
for which i am not sure what i am doing wrong.Also this is the function I am trying to call
Oracle Function
FUNCTION FXRATE_ENTITY(CODCURRBASE IN VARCHAR, LCODCURRFROM IN VARCHAR, LCODCURRTO IN VARCHAR, LIDENTITY IN VARCHAR)
RETURN NUMBER IS
CODCUR_L VARCHAR2(3);
BEGIN
IF (LCODCURRTO = '*') THEN
RETURN NVL(FXRATE(CODCURRBASE, LCODCURRFROM, CODCURRBASE, LIDENTITY),
0);
ELSE
RETURN NVL(FXRATE(CODCURRBASE, LCODCURRFROM, LCODCURRTO, LIDENTITY), 0);
END IF;
END;
Any help or suggestions will be appreciated. Thanks in advance.
You have an extra ?
in the prepare call statement which is not required as the first parameter is considered as the return parameter, so registering the out parameter using registerOutParameter
is what we need.
Change the statement to below and it should work,
CallableStatement cstmt = p_con.prepareCall("{? = CALL FXRATE_ENTITY(?, ?, ?, ?)}");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.