请教spring怎么调用oracle函数,帮忙看一下这样行吗

请问spring如何调用oracle函数,帮忙看一下这样行吗
网上查了一个调用的方法,不知道哪里错了,哪位大侠帮忙看一下哪里错了


@SuppressWarnings("unchecked")
public String ExecuteFunc(final String checkUnit,final String idCard){
 String param2Value = (String) getSimpleJdbcTemplate().getJdbcOperations().execute(   
     new CallableStatementCreator() {   
        public CallableStatement createCallableStatement(Connection con) throws SQLException {   
           String storedProc = "{call fn_fjxx_saftyreport (?,?)}";// 调用的sql   
           CallableStatement cs = con.prepareCall(storedProc);   
           cs.setString(2, checkUnit);// 设置输入参数的值   
           cs.setString(3, idCard);
           cs.registerOutParameter(1,OracleTypes.VARCHAR);// 注册输出参数的类型   
         
           return cs;   
        }   
     }, new CallableStatementCallback() {   
         public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {   
           cs.execute();   
           return cs.getString(2);// 获取输出参数的值   
     }   
  });
return param2Value; 

运行出现错误:
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL []; SQL state [72000]; error code [1006]; ORA-01006: 绑定变量不存在
; nested exception is java.sql.SQLException: ORA-01006: 绑定变量不存在
更多 0
------解决方案--------------------
   cs.setString(1, checkUnit);// 设置输入参数的值   
           cs.setString(2, idCard);
           cs.registerOutParameter(3,OracleTypes.VARCHAR);// 注册输出参数的类型     看看
------解决方案--------------------
call fn_fjxx_saftyreport (?,?)楼主你这里就两个参数,你却设置了三个。你这个如果是函数不是存储过程,而且函数有返回值的话,直接用普通的PrepareStatement 来select fn_fjxx_saftyreport (?,?)就可以了不要用call
------解决方案--------------------
引用:
  cs.registerOutParameter(1,OracleTypes.VARCHAR);// 注册输出参数的类型   这个不是输出用的吗

输出用的也要占一个函数有返回值的直接用普通的PrepareStatement 来select fn_fjxx_saftyreport (?,?)就可以了不要用call
如果你非要用call那你得改成{?=call fn_fjxx_saftyreport (?,?)}这样才有三个参数,第一个参数就是用来接收你函数返回值的也是你的输出参数
------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

不行,出错了
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [select fn_fjxx_saftyreport (?,?)]; nested exception is java.sql.SQLException: ORA-00923: 未找到要求的 FROM 关键字

下次回复的时候,请引用要不然看不到的。
忘记了你是oracle,那你得这么用
String param2Value =getSimpleJdbcTemplate().getJdbcOperations().query("select fn_fjxx_saftyreport (?,?) from dual", new Object[]{checkUnit,idCard}, new ResultSetExtractor<String>(){
    public String extractData(ResultSet rs) {
       if(rs.next()) return rs.getString(1);
      else return null;
    }
}) ;

我那是函数,可以用select  from dual吗

就因为你是oracle的函数才加from dual,这是oracle函数调用的sql写法,这个楼主不该问google就能知道了