/*
*我们从数据库中取字符串值时,后面会有许多空格,需要特别注意
*
*/
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
/*#define SQLCA_NONE*/
EXEC SQL INCLUDE SQLCA;
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
int sysid;
int intId;
char name[256];
char connString[] = "nmc/nmc@atest_229";
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT :connString;
if(sqlca.sqlcode != 0)
{
printf("connect database error!ORA ERROR: %s/n", sqlca.sqlerrm.sqlerrmc);
exit(1);
}
memset(name, '/0', sizeof(name));
EXEC SQL SELECT ne_name into :name
FROM objects_exs
WHERE int_id = 13650039;
if(sqlca.sqlcode == 1403)
{
printf("No data found! ORA ERROR: %s", sqlca.sqlerrm.sqlerrmc);
exit(1);
}
printf("ne_name=%s/n", name); //打印出name值,后面会有许多空格。因为name定义为256个字符,而ne_name值不够256,后面全用空格代替,打印出的字符长度也为256
//去掉name后面的空格
char *p=name;
while(*p != ' ')
p++;
*p = '/0';
printf("ne_name=%s/n", name);
EXEC SQL COMMIT WORK RELEASE;
return 0;
}