我有以下C代码,它使用存储过程将2个字符串插入数据库:
char query[1024];
memset(query, 0, sizeof(query));
sprintf(query, "BEGIN bns_saa_message_insert (:1, :2); END;");
/* prepare statement */
if( checkerr(errhp, OCIStmtPrepare(stmthp, errhp, (text *) query,
(ub4) strlen((char *) query),
(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT)) == OCI_ERROR)
return -1;
/* bind input params */
if( checkerr(errhp, OCIBindByPos(stmthp, &bndhp, errhp, (ub4) 1, (dvoid *) hostNumber,
(sword) sizeof(hostNumber) - 1, SQLT_CHR, (dvoid *) 0,
(ub2 *) 0, (ub2) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT)) == OCI_ERROR)
return -1;
if( checkerr(errhp, OCIBindByPos(stmthp, &bndhp, errhp, (ub4) 1, (dvoid *) saaMessage,
(sword) sizeof(saaMessage) - 1, SQLT_CHR, (dvoid *) 0,
(ub2 *) 0, (ub2) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT)) == OCI_ERROR)
return -1;
//end of param binding
printf(“查询:%s”,查询); //这表示当我执行上面的绑定时,param1和param2尚未被替换
/* execute the statement */
status = OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0,
(CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT);
我得到的错误是:
ORA-01008:并非所有变量都绑定
以及上面代码中列出的printf输出:
查询:BEGIN bns_saa_message_insert(:1,:2); END;
问题
如何解决此错误?
修改
我在C#或Java中看到了类似的问题,但不是C
"ORA-01008: not all variables bound" error
ORA-01008: not all variables bound. They are bound
答案 0 :(得分:4)
这看起来像是一个小错误。您对OCIBindByPos
的第二次通话应使用2
代替1
作为第四个参数:
if( checkerr(errhp, OCIBindByPos(stmthp, &bndhp, errhp, (ub4) 2, (dvoid *) saaMessage,