How to call a stored procedure with a parameter of type table How to call a stored procedure with a parameter of type table oracle oracle

How to call a stored procedure with a parameter of type table


You are almost there!

  1. Create object representations of your oracle types using the Object Type Translator utility OTT

  2. Create a vector of pointers to the OTT created type and use the OCCI call setVector() on the statement

  3. Execute!

Here is a small code example:

#include <occi.h>#include <iostream>#include "RegisterMappings.h"using namespace oracle::occi;using namespace std;void callproc(Connection *con){      vector<my_obj_t *> vect;      int i;      for (i=0; i<10; i++)      {            my_obj_t *obj = new my_obj_t();            obj->setid(i);        obj->setname("TEST");        vect.push_back(obj);    }      cout << "\ncallproc - invoking a PL/SQL procedure with parameters"  << endl;      Statement *stmt = con->createStatement("BEGIN my_proc(:1); END;");      cout << "\nExecuting the block :" << stmt->getSQL() << endl;      setVector(stmt, 1, vect, "MY_OBJ_TAB_T");      stmt->execute();      con->terminateStatement (stmt);      cout << "\nocciproc - done" << endl;     // delete allocated memory    for (i=0; i<10; i++)      {            delete vect[i];    }  }// end of callproc ()int main(){try {    Environment* env = Environment::createEnvironment(Environment::OBJECT);      RegisterMappings(env);      Connection* conn = env->createConnection("scott","tiger");      callproc(conn);   conn->commit();      env->terminateConnection(conn);      Environment::terminateEnvironment(env);    }    catch(SQLException &ex)    {          cout << ex.getMessage() << endl;    }}