This may have been asked before, so I’m sorry if this is repeated. If you can link to where I can find an answer, I would really appreciate it. I’ve looked around at other answers and on Google but nothing seems to have worked yet.
So…
I have a stored procedure in Oracle 11g (that I cannot change) and I have to use OCI (no choice here).
The stored procedure declaration is like:
PROCEDURE GetEmployee(EID IN NUMBER, rcursor IN OUT cursor_type);
How do I call this in C?
I tried to use the OCI example here as a basis, modifying it so:
char * query = "DECLARE \
EID NUMBER; \
RCURSOR CORP.EMPASSIST.cursor_type; \
BEGIN \
EID:= NULL; \
RCURSOR := NULL; \
EMPASSIST.GetEmployee( EID=> EID, RCURSOR => RCURSOR ); \
:RCURSOR := RCURSOR; --<-- Cursor \
END;";
OCIError * db_error;
OCIStmt * statement;
OCIEnv * environment;
OCIServer * server;
OCISession * session;
OCISvcCtx * service;
OCIBind * cursor_bind;
OCIBind * eid_bind;
OCIStmt * cursor_stm;
OCIStmt * eid_stm;
retval += OCIStmtPrepare(statement, db_error, (OraText *) query, strlen(query), OCI_NTV_SYNTAX, OCI_DEFAULT);
retval += OCIHandleAlloc(environment, (void **) &eid_stm, OCI_HTYPE_STMT, 0, NULL);
retval += OCIHandleAlloc(environment, (void **) &cursor_stm, OCI_HTYPE_STMT, 0, NULL);
retval += OCIBindByPos(statement, &eid_bind, db_error, 1, &eid_stm, 0, SQLT_NUM, NULL, 0, NULL, 0, 0, OCI_DEFAULT);
retval += OCIBindByPos(statement, &cursor_bind, db_error, 2, &cursor_stm, 0, SQLT_RSET, NULL, 0, NULL, 0, 0, OCI_DEFAULT);
retval += OCIStmtExecute(service, statement, db_error, 1, 0, NULL, NULL, OCI_COMMIT_ON_SUCCESS);
but this does not seem to work for me. All the handle allocation seems to work just fine. No errors.
However, it fails on the OCIStmtExecute step. I have to BindByPos after that, and they fail too, but I’m guessing that is because of the statement execution failure.
Please help!
==========================================================================
Fixed: Posting in answers in case it helps someone else
Changed:
to
Changed the rest to: