【问题标题】:ORA-01008: not all variables bound (in C w OCI)ORA-01008: 并非所有变量都绑定(在 C w OCI 中)
【发布时间】:2012-03-01 05:45:26
【问题描述】:

我有以下 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("query: %s",query);//这说明我上面绑定的时候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);结束;

问题
如何解决此错误?

编辑
我在这里看到了用 C# 或 Java 回答的类似问题,但不是 C
"ORA-01008: not all variables bound" error
ORA-01008: not all variables bound. They are bound

【问题讨论】:

  • printf 语句的输出不相关。查询和参数分别传输到服务器。并且查询和它的执行计划被缓存在服务器端,没有具体的参数。这是整体概念的一部分。

标签: c oracle oracle-call-interface


【解决方案1】:

这似乎是一个小错误。您对OCIBindByPos 的第二次调用应使用2 而不是1 作为第四个参数:

if( checkerr(errhp, OCIBindByPos(stmthp, &bndhp, errhp, (ub4) 2, (dvoid *) saaMessage,

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2020-05-06
    • 2011-09-22
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 2014-01-29
    相关资源
    最近更新 更多