我想调用一个存储过程,它具有TABLE类型的参数.
如何在 Windows C应用程序中使用OCCI(11g1)执行此操作?
如何在 Windows C应用程序中使用OCCI(11g1)执行此操作?
这是存储过程的定义:
FUNCTION am_send( p_caFnr IN VARCHAR2,p_TabBgr IN DSKS_BGR_TAB,p_caTextout OUT VARCHAR2) RETURN NUMBER;
和使用的类型:
create or replace TYPE DSKS_BGR_TAB,AS TABLE OF DSKS_BGR create or replace TYPE DSKS_BGR (BgrNr VARCHAR2(3),TrId VARCHAR2(8))
到目前为止我做了什么:
我使用OTT实用程序创建了一个DSKS_BGR类型的对象表示.
我的代码到目前为止:
Environment* env = Environment::createEnvironment(Environment::OBJECT); try { Connection *con = env->createConnection("xxxxx","xxxxx","xxxxx"); Statement* statement = con->createStatement("BEGIN :1 := am_send(:2,:3,:4); END;"); statement->registerOutParam(1,OCCINUMBER); statement->setString(2,"Test"); // ?? DSKS_BGR_TAB statement->registerOutParam(4,OCCISTRING,1000); statement->execute(); int result = statement->getNumber(1); string textOut = statement->getString(4); env->terminateConnection(con); } catch(const sqlException &exc) { cout << exc.getErrorCode() << exc.getMessage(); } Environment::terminateEnvironment(env);
我不知道如何设置TABLE参数.
解决方法
你快到了!
>使用对象类型转换器实用程序OTT创建oracle类型的对象表示
>创建指向OTT创建类型的指针向量,并在语句上使用OCCI调用setVector()
>执行!
这是一个小代码示例:
#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; } }