2012-02-08 23 views
0

我有一個使用的存儲過程中插入2串到數據庫中的下面的C代碼:ORA-01008:未結合(在C瓦特OCI)所有變量

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(「查詢:%的」,查詢); //這表明參數1和參數當我做了上述

/* 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

+2

了'printf'語句的輸出是不相關的。查詢和參數分別傳輸到服務器。查詢和它的執行計劃緩存在服務器端,沒有特定的參數。這是整體概念的一部分。 – Codo 2012-02-08 18:36:23

回答

4

它看起來像一個小的失誤。您對OCIBindByPos秒調用應使用2而不是1第四參數:

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