Oracle OCIBindByPos() for out bind variables

Oracle OCIBindByPos() for out bind variables

本文关键字:out bind variables for OCIBindByPos Oracle      更新时间:2023-10-16

有没有关于如何使用OCI绑定变量的好文档?我在绑定绑定变量时遇到问题。buf 在存储过程中与"OUT"变量绑定。

问题 1:是否需要为buf预先分配内存?或者 OCI 可以做到这一点?

问题2:有没有办法知道buf中存储了多少字节的字符?或者只是将其视为以 null 结尾的 C 字符串?

int pos; 
char* buf; 
size_t len;
int rc = OCIBindByPos( Stmt, &bind, errhp, pos, buf, len, SQLT_STR,
                       NULL, NULL, NULL, 0, NULL, OCI_DEFAULT );

问题 1:我需要为 buf 预分配内存吗?或者 OCI 可以做到这一点?是的,你当然需要。您需要使用 OCIHandle

OCIHandleAlloc((dvoid *)OCIEnv, (dvoid **)&OCIStmt, OCI_HTYPE_STMT, len, 
                      (dvoid **)&buf);

问题 2:有没有办法知道 buf 中存储了多少字节的字符?或者只是将其视为以 null 结尾的 C 字符串?

OCIBindByPos

你告诉多少字节。