Reputation: 1346
I have a procedure with the following signature:
procedure countryExists(iCountryName in varchar2, oCount out integer)
When I run it using OCILIB, I can't get the right value for oCount. If I register it as integer (using OCI_RegisterInt), I get the error:
ORA-03116: invalid buffer length passed to a conversion routine
If I register it as a string, it runs, but OCI_GetString returns a null pointer and OCI_GetInt returns 0 (instead of the expected result 1).
The test code is:
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);
Running the procedure using, for example, PL/SQL Developer works fine.
Is this the right way of calling procedures using OCILIB?
Also note that I'm using the mixed version of the library.
Upvotes: 0
Views: 2467
Reputation: 26
You're not coding in Java....
Here is the right way to do it :
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);
Check the OCILIB documentation and/or manual
Vincent
Upvotes: 1