0

次の署名のある手順があります。

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を使用してプロシージャを呼び出す正しい方法ですか?

また、ライブラリの混合バージョンを使用していることにも注意してください。

4

1 に答える 1

1

あなたはJavaでコーディングしていません....

これを行う正しい方法は次のとおりです。

OCI_Connection *cn;
OCI_Statement  *st;
int count;

OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT|OCI_ENV_CONTEXT);

cn = OCI_ConnectionCreate("mydb", "myuser", "mypass", OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn);

OCI_Prepare(st, "begin mypackage.countryExists('BRAZIL', :oCount); end;");
OCI_BindInt(st, ":oCount", &count);
OCI_Execute(st);

OCILIBのドキュメントおよび/またはマニュアルを確認してください

ヴィンセント

于 2011-10-04T20:36:05.423 に答える