title: Error OCI_INVALID_HANDLE in Oracle OCI C Code
body: <p>I get an error of invalid Handle when <code>OCIStmtFetch2</code> function executes in my code. </p>
  
  <pre><code>char *query = "SELECT id FROM id_table WHERE ROWNUM &lt;= :1";
  rc = OCIStmtPrepare(stmt, errhp, (OraText*)query, strlen(query), OCI_NTV_SYNTAX, OCI_DEFAULT);
  
  OCIBind *bindp = NULL;
  sb2 pos = 1;
  int key=13;
  rc = OCIBindByPos(stmt, &amp;bindp, errhp, 1, &amp;key, sizeof(int), SQLT_INT, (dvoid*)&amp;pos, NULL, NULL, 0, NULL, OCI_DEFAULT);
  
  char output[key][120];
  sb2 output_ind[1];
  ub2 output_len[1];
  ub2 output_code[1];
  OCIDefine *defnpp;
  rc = OCIDefineByPos(stmt, &amp;defnpp, errhp, 1, (dvoid*)output, 120, SQLT_STR, (dvoid*)output_ind, output_len, output_code, OCI_DEFAULT);
  
  int rows = key;
  /* execute */
  rc = OCIStmtExecute(svchp, stmt, errhp, key, 0, NULL, NULL, OCI_DEFAULT);
  
  
  rc = OCIStmtFetch2(stmt, errhp, 0, OCI_DEFAULT, 0, OCI_DEFAULT);
  </code></pre>
  
  <p>If I bind the placehoder :1 with integer value 12 then the code works, any value greater than 12 gives me <code>Error OCI_INVALID_HANDLE</code> error after running <code>OCIStmtFetch2</code>. I have the following code to catch error, which I run after each OCI functions mentioned in the code above</p>
  
  <pre><code>if (rc != OCI_SUCCESS &amp;&amp; rc != OCI_SUCCESS_WITH_INFO) {
    report_error(checkerr("Function Name()", errhp, rc));
    return 1;
  }
  </code></pre>
  
  <p>Can anyone please help me what is incorrect in my code? Thank you!</p>