次の署名のある手順があります。
procedure countryExists(iCountryName in varchar2, oCount out integer)
OCILIBを使用して実行すると、oCountの正しい値を取得できません。(OCI_RegisterIntを使用して)整数として登録すると、次のエラーが発生します。
ORA-03116:変換ルーチンに渡されたバッファ長が無効です
文字列として登録すると実行されますが、OCI_GetStringはnullポインタを返し、OCI_GetIntは(期待される結果1ではなく)0を返します。
テストコードは次のとおりです。
int init = OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT|OCI_ENV_CONTEXT);
OCI_Connection *cn = OCI_ConnectionCreate("mydb", "myuser", "mypass", OCI_SESSION_DEFAULT);
OCI_Statement *st = OCI_StatementCreate(cn);
int resultprepare = OCI_Prepare(st, "call mypackage.countryExists('BRAZIL', :oCount)");
//int registercount = OCI_RegisterString(st, ":oCount", 100);
int registercount= OCI_RegisterInt(st, ":oCount");
int executeresult = OCI_Execute(st);
OCI_Error *err1 = OCI_GetLastError();
const char *error1 = OCI_ErrorGetString(err1);
OCI_Resultset *resultset = OCI_GetResultset(st);
const wchar_t *valstr = OCI_GetString(resultset, 1);
int valint = OCI_GetInt(resultset, 1);
OCI_Error *err2 = OCI_GetLastError();
const char *error2 = OCI_ErrorGetString(err2);
たとえば、PL /SQLDeveloperを使用してプロシージャを実行すると正常に動作します。
これは、OCILIBを使用してプロシージャを呼び出す正しい方法ですか?
また、ライブラリの混合バージョンを使用していることにも注意してください。