title: java.sql.SQLSyntaxErrorException: ORA-01722: invalid number while resultSet.next() on refcursor and I don't understand why?
body: <p>I have an issue eating me for hours and I'm unable to find the exact reason why it is happening?
  I get <em>java.sql.SQLSyntaxErrorException: ORA-01722: invalid number</em> while iterating over refcursor out parameter of stored procedure using ResultSet.next().
  What is bothering me is, it occurs even when there is actually no result to iterate over.</p>
  
  <p>The signature of stored procedure:</p>
  
  <pre><code>PROCEDURE GET_PROG_SRCH_BY_CRITERIA
         (p_orgID                  IN    NUMBER,
          p_MEPID                  IN    NUMBER,
          p_prog_prg_id            IN    NUMBER,
          p_pcom_enrol_date        IN    VARCHAR2,
          p_pcom_enrol_year_from   IN    VARCHAR2,
          p_pcom_enrol_year_to     IN    VARCHAR2,
          p_pcom_non_prtcm_date    IN    VARCHAR2,
          p_pcom_completion_date   IN    VARCHAR2,
          p_pcom_status_code       IN    VARCHAR2,        
          p_sys_cursor             OUT   SYS_REFCURSOR
         );
  </code></pre>
  
  <p>Java code snippet:</p>
  
  <pre><code>statement = connection.prepareCall("call PROG_TOOLS.GET_PROG_SRCH_BY_CRITERIA(?,?,?,?,?,?,?,?,?,?)");
  statement.setLong(1, searchCriteria.getOrganizationID());
  /*
   * Code to Set other 8 Parameters comes here
   */
  statement.registerOutParameter(10, oracle.jdbc.OracleTypes.CURSOR);
  statement.executeQuery();
  resultSet = (ResultSet) statement.getObject(10);
  /*
   * Code to Initialize necessary value Objects comes here
   */
  while (resultSet.next()) {
      /*
       * Code to get values from resultSet using column named index
       * and initialize value objects
       * Few example:
       */
       dataVO = new DataVO();
       dataVO.setPcomID(result.getLong("PCOM_ID"));
       dataVO.setPersonID(result.getLong("PERSON_ID"));
       .
       .
       programList.add(dataVO);
  }
  </code></pre>
  
  <p>Issue:
  If I call GET_PROG_SRCH_BY_CRITERIA by sending NULL in 3rd parameter, I get expected result.
  If I call GET_PROG_SRCH_BY_CRITERIA by sending an actual value in 3rd parameter, I get <em>java.sql.SQLSyntaxErrorException: ORA-01722: invalid number</em> on the line </p>
  
  <blockquote>
    <p>while (resultSet.next()) {</p>
  </blockquote>
  
  <p>Exception trace:</p>
  
  <pre><code>java.sql.SQLSyntaxErrorException: ORA-01722: invalid number
      at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
      at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
      at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1030)
      at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:183)
      at oracle.jdbc.driver.T4CStatement.fetch(T4CStatement.java:1000)
      at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:314)
      at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:228)
      at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.next(Unknown Source)
      at org.app.ejb.program.dao.ProgDAO.searchProgEnrollees(ProgDAO.java:136)
  </code></pre>
  
  <p>I checked the procedure by testing it directly using SQLDeveloper tools by sending the same parameters which the above Java code used. It worked absolutely fine.</p>
  
  <p>I tried with OJDBC14 and OJDBC6 drivers, but no luck.</p>
  
  <p>I have no clue why this occurs on resultSet.next(). If the 3rd parameter is null then I don't get this exception and flow works as expected.</p>
  
  <p>Any help here is really appreciated.</p>
  
  <p>Technologies used:
   - Java 6, ejb
   - Oracle 11g Database R2 (11.2.0.3)
   - Oracle Weblogic 10g (10.3.0)</p>