Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8411135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:21:52+00:00 2026-06-10T00:21:52+00:00

This may have been asked before, so I’m sorry if this is repeated. If

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:21:54+00:00Added an answer on June 10, 2026 at 12:21 am

    Changed:

    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;"; 
    

    to

    int eid = /* whatever value */;
    char * query_template = "CALL EMPASSIST.GetEmployee(%d, :RCURSOR)";
    char query[1023] =  {'\0'};
    snprintf(query, sizeof(query) - 1, query_template, eid);
    

    Changed the rest to:

    OCIError * db_error;   
    OCIStmt * statement;   
    OCIEnv * environment;   
    OCISvcCtx * service;   
    
    OCIBind * cursor_bind;   
    OCIStmt * cursor_stm;   
    
    retval += OCIHandleAlloc(environment, (void **) &statement, OCI_HTYPE_STMT, 0, NULL);
    retval += OCIStmtPrepare(statement, db_error, (OraText *) query, strlen(query), OCI_NTV_SYNTAX, OCI_DEFAULT);   
    retval += OCIHandleAlloc(environment, (void **) &cursor_stm, OCI_HTYPE_STMT, 0, NULL);   
    retval += OCIBindByName(statement, &cursorbind, db_error, (OraText *) ":RCURSOR", strlen(":RCURSOR"), &cursor, 0, SQLT_RSET, 0, 0, 0, 0, 0, OCI_DEFAULT);   
    
    retval += OCIStmtExecute(service, statement, db_error, 1, 0, NULL, NULL, OCI_COMMIT_ON_SUCCESS);   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may have been asked before, but I could not find the answer. I
This may have been asked before and I just can't find it. I have
This question may have been asked before, but I couldn't find an answer to
This question may have been asked before, but I had trouble finding an answer,
This question may have been asked before and I'm sorry if I missed it,
this may have been asked already but I cant really find it (most likely
This may have been asked before, but it's really hard to search for terms
This question may well have been asked before but I didn't find anything whilst
This question has been asked before, but I can't find any answers that have
this may have been asked before, but I could not find it. Suppose I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.