昨天代码里报错数据库在插入的时候报错 ”ORA-12899” 我打印了一下变量看了一下,读取到的变量都填充了空格,一开始的时候怀疑是没有初始化,后来初始化了变量还不行,后来就写了一个例子发现空格是oracle 带过来,询问同事解决办法。。。。
#include<stdio.h>
#include<string.h>
exec sql include sqlca;
exec sql include oraca;
int main(void)
{
exec sql begin declare section;
char userpwd[40] = "xDB";
int id;
char termbh[20] = {0};
exec sql end declare section;
exec sql connect:userpwd;
if(sqlca.sqlcode == 0)
{
printf("connect sucess!\n");
}
else
{
printf("connect error!\n");
}
char bh[9]= "88423368";
printf("termbh = %s, %d\n", termbh, strlen(termbh));
exec sql select TERMBH, length(TERMBH) into:termbh,:id from ** where termbh =:bh;
printf("termbh = %s, %d\n", termbh, strlen(termbh));
printf("termbh=%s|, id=%d\n", termbh, id);
printf("strlen = %d\n", strlen(termbh));
==========================================================================
结果:
connect sucess!
termbh = , 0
termbh = 88423368 , 19
termbh = 88423368 |, id=8
strlen = 19
如果在代码的第四行后面加上 如下代码:
exec oracle option(oraca = yes);
exec oracle option(release_cursor=yes);
exec oracle option(char_map=string); // 这句话起到作用
结果就是你想的那个样子了。
connect sucess!
termbh = , 0
termbh = 88423368, 8
termbh=88423368|, id=8
strlen = 8