OCI批量 新增 数据时数据长度的问题

CHID CHID 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
字段q_id的类型为varchar(45),更新数据时,如果q_id字符串的长度刚好为45时,没有问题,可实际上q_id字符串的长度可能小于45,例如当q_id="ID1000"时,实际存入数据库中的值为"ID1000"+乱码,怎么解决?
表结构:
create table testtable
(
q_id varchar(45),
qq_flag varchar(2),
qvalue decimal(20,2)
)
批量新增数据的函数:


int OCI_TOOLS::ORA_BindArrayWithupdatead(char *buff, float qvalue[], char q_id[][45],char qq_flag[][2],int maxiter)
{
text *sqltext;
int i;
sword ret1,ret2,ret3,ret4;
text msgbuf[512];

/* bind handles will be implicitly allocated in the bind calls */
/* need to initialize them to null prior to first usage in bind calls */

OCIBind *bnd1p = (OCIBind *) 0; /* the first bind handle */
OCIBind *bnd2p = (OCIBind *) 0; /* the second bind handle */
OCIBind *bnd3p = (OCIBind *) 0; /* the third bind handle */

text *sqlstmt = (text *)buff;

if (OCIStmtPrepare(stmthp, errhp, sqlstmt, (ub4)strlen((char *)sqlstmt),
(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))
{
(void) printf("FAILED: OCIStmtPrepare() update\n");
//report_error(errhp);
return OCI_ERROR;
}
ret1=OCIBindByPos(stmthp, &bnd1p,errhp, (ub4) 1,
(dvoid *) qvalue, (sb4) 4, SQLT_FLT,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT);

ret3=OCIBindByPos(stmthp, &bnd3p,errhp, (ub4) 3,
(dvoid *) q_id, (sb4) 45, SQLT_CHR,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT);

ret2=OCIBindByPos(stmthp, &bnd2p,errhp, (ub4) 2,
(dvoid *) qq_flag, (sb4) 2, SQLT_CHR,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT);


if (ret1||ret2||ret3)
{
(void) printf("FAILED: OCIBindArrayOfStruct()\n");
//report_error(errhp);
return OCI_ERROR;
}

ret1=OCIBindArrayOfStruct(bnd1p,errhp, 4, 0, 0, 0);
ret3=OCIBindArrayOfStruct(bnd3p,errhp, 45, 0, 0, 0);
ret2=OCIBindArrayOfStruct(bnd2p,errhp, 2, 0, 0, 0);

if (ret1||ret2||ret3)
{
(void) printf("FAILED: OCIBindArrayOfStruct()\n");
//report_error(errhp);
return OCI_ERROR;
}



if (OCIStmtExecute(svchp, stmthp,errhp, (ub4) maxiter, (ub4) 0,
(CONST OCISnapshot*) 0, (OCISnapshot*) 0,
(ub4) OCI_COMMIT_ON_SUCCESS))
{
(void) printf("FAILED: OCIStmtExecute() update ccbase\n");
//report_error(errhp);
sb4 errcode = 0;
(void) OCIErrorGet((dvoid *) errhp, (ub4) 1, (text *) NULL, &errcode,
msgbuf, (ub4) sizeof(msgbuf), (ub4) OCI_HTYPE_ERROR);
(void) printf("ERROR CODE = %d\n", errcode);
(void) printf("%.*s\n", 512, msgbuf);
return OCI_ERROR;
}
status=OCITransCommit(svchp,errhp,0);
if(status!=OCI_SUCCESS)
{
error_proc(errhp,status);
return OCI_FAIL;
}

return OCI_SUCCESS;
}
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
CHID
数据库 4,017 成员 39,805 内容