Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> OCI Array Binding problem
Hello,
I have a stored proc that accepts as input an array of varchar2(256) and returns a varchar as an out parameter. I get this error message when I call it from my code-
ORA-01485: compile bind length different from execute bind length
I have no idea where and how to fix this. Please let me know if you have any suggestions or ideas.
Here is the code:
#include <stdio.h> #include <stdlib.h> #include <string.h>
#define __STDC__ 0
#include <oci.h>
//#pragma comment(lib, "d:\\orant805\\oci80\\lib\\msvc\\ora803.lib") #pragma comment(lib, "d:\\orant805\\oci80\\lib\\msvc\\oci.lib")
OCIEnv *p_env; OCIError *p_err; OCISvcCtx *p_svc; OCIStmt *p_sql; OCIBind *p_bnd; OCIBind *p_bnd2;
int rc = 0;
char v_val[3][256] = {"Hello World", "Hello World1", "Hello World2"};
ub2 mlena[3] = { 256, 256, 256 };
char *v_out;
int error(int rc);
int main()
{
rc = OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0,
(dvoid * (*)(dvoid *, size_t)) 0,
(dvoid * (*)(dvoid *, dvoid *, size_t))0,
(void (*)(dvoid *, dvoid *)) 0 );
rc = OCIEnvInit( (OCIEnv **) &p_env, OCI_DEFAULT, (size_t) 0, (dvoid **) 0 );
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_err,
OCI_HTYPE_ERROR,
(size_t) 0, (dvoid **) 0);
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_svc,
OCI_HTYPE_SVCCTX,
(size_t) 0, (dvoid **) 0);
char* v_usr = "testUser"; char* v_pwd = "testPwd"; char* v_tns = "testDb";
rc = OCILogon(p_env, p_err, &p_svc, (OraText *) v_usr, strlen
(v_usr),
(OraText *) v_pwd, strlen(v_pwd), (OraText *) v_tns,
strlen(v_tns));
error(rc);
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_sql, OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
char* v_sql = "begin arrtest.arrInput(:x, :y); end;";
rc = OCIStmtPrepare(p_sql, p_err, (OraText *) v_sql, (ub4)
strlen(v_sql),
(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);
error(rc);
ub4 v_val_cnt = sizeof(v_val);
rc = OCIBindByPos(p_sql, &p_bnd, p_err, 1,
(dvoid *) &v_val[0][0],
(sb4) 256,
SQLT_STR,
(dvoid *) 0,
(ub2 *)&mlena,
(ub2 *) 0,
(ub4) 3, // indicates the maximum arraysize
(ub4 *) &v_val_cnt, // recieves the number of elements used
OCI_DEFAULT);
error(rc);
rc = OCIBindArrayOfStruct(p_bnd, p_err, (sb4)256, 0, (ub4) 2 , 0);
error(rc);
ub2 data_len = static_cast<sb2> (1024);
rc = OCIBindByPos(p_sql, &p_bnd2, p_err, 2,
v_out,
(sb4) 1024,
SQLT_STR,
(dvoid *) 0,
&data_len,
(ub2 *) 0,
(ub4) 0, // indicates the maximum arraysize
(ub4 *) 0, // recieves the number of elements used
OCI_DEFAULT);
error(rc);
rc = OCIStmtExecute(p_svc, p_sql, p_err, (ub4) 1, (ub4) 0,
(CONST OCISnapshot *) NULL, (OCISnapshot *) NULL,
OCI_DEFAULT);
error(rc);
printf("%25s\n",&v_out);
// Disconnect from the server and free the
rc = OCILogoff(p_svc, p_err); rc = OCIHandleFree((dvoid *) p_sql, OCI_HTYPE_STMT); rc = OCIHandleFree((dvoid *) p_svc, OCI_HTYPE_SVCCTX); rc = OCIHandleFree((dvoid *) p_err, OCI_HTYPE_ERROR);
return 0;
}
int error(int rc)
{
// This is a generic error checking routine
char errbuf[100];
int errcode;
if (rc != 0)
{
OCIErrorGet((dvoid *)p_err, (ub4) 1, (OraText *) NULL,
(sb4 *)&errcode,
(OraText *) errbuf, (ub4) sizeof(errbuf),
OCI_HTYPE_ERROR);
printf("Error - %2525.*s\n", 512, errbuf);
exit(0);
}
return 0;
}
Thanks, SR Received on Tue Oct 12 2004 - 19:40:39 CDT