I am using NamedParameterJdbcTemplate for run pl/sql script.
But I don’t know how can I get the values of out variables (:id_out).
Thanks in advance.
String script = "declare
begin
if myFunc(:id_in) is null then
:id_out := 0;
else
:id_out := 1;
end if;
end;";
Map<String,Object> bindVars = new HashMap<String, Object>();
bindVars.put(id_in,1);
bindVars.put(id_out,2);
jdbcTmpl.execute(script, bindVars, new PreparedStatementCallback<Object>() {
@Override public Object doInPreparedStatement(PreparedStatement cs)
throws SQLException, DataAccessException {
cs.execute();
return null;
}
}
);
I don’t believe you can use a NamedParameterJdbcTemplate (or any other subclass of JdbcTemplate) with anonymous PL/SQL blocks such as that above. You’ll have to wrap your anonymous PL/SQL block into a stored procedure or function.
Spring is intended to be portable across databases. As far as I know, neither MySQL nor SQL Server have a concept analogous to Oracle’s anonymous PL/SQL blocks (I’m happy to be proved wrong on this point, though). Since this feature isn’t portable across databases, Spring can’t really support it for just Oracle.