- 论坛徽章:
- 0
|
ORACLE 函数代码, 用out参数返回一个数组
- CREATE OR REPLACE TYPE OBJ AS OBJECT ( Id NUMBER(10), name VARCHAR2(32) );
- CREATE OR REPLACE TYPE OBJ_ARRAY AS TABLE OF OBJ;
- CREATE OR REPLACE FUNCTION GetCollection (objs OUT OBJ_ARRAY) RETURN BINARY_INTEGER AS
- vret BINARY_INTEGER;
- BEGIN
- objs := OBJ_ARRAY();
- for i in 1..5
- loop
- objs.extend();
- objs(objs.Last) := OBJ(i, "test");
- end loop;
- vret := 0;
- RETURN vret;
- END GetCollection;
复制代码
C++代码, 调用ORACLE函数, 并用getVector 取出数组,结果捕获到OCI-21500错误!
- #include <stdlib.h>
- #include <occi.h>
- #include <iostream>
- #include <string>
- #include <stdexcept>
- #include "ott/map.h"
- using namespace oracle::occi;
- using namespace std;
- int main(int argc, char** argv)
- {
- try
- {
- string user = "test";
- string passwd = "test";
- string db = "test";
- Environment* env = Environment::createEnvironment (Environment::OBJECT);
- map(env);
- Connection* conn = env->createConnection (user, passwd, db);
- Statement* stmt = conn->createStatement("BEGIN :1 := GetCollection(:2); END;") ;
- stmt->registerOutParam(1, OCCIINT);
- stmt->registerOutParam(2, OCCIVECTOR, 0, "OBJ_ARRAY");
- stmt->execute();
- int code = stmt->getInt(1);
- cout << "RetCode = " << code << endl; -- Prints "RetCode = 0"
- std::vector< RefAny > vObjs;
- getVector(stmt, 2, vObjs); -- 执行到这行时, 捕获 OCI-21500: 而且还是内部错误.
- conn->terminateStatement(stmt);
- env->terminateConnection(conn);
- Environment::terminateEnvironment(env);
- }
- catch(SQLException& ex)
- {
- cerr << "Program raised exception " << ex.getErrorCode()
- << " with text:" << endl << ex.getMessage().c_str() << endl;
- return EXIT_FAILURE;
- }
- catch(std::exception& ex)
- {
- cerr << "Program raised std::exception: " << ex.what() << endl;
- return EXIT_FAILURE;
- }
- catch(...)
- {
- cerr << "Unhandled exception." << endl;
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS
- }
复制代码 |
|