开发者社区> 问答> 正文

otl连接数据库时,取number类型数据时,需要to_char,为何??报错

问题描述:
使用OTL的pro*c方法连接Oracle数据库时,取NUMBER 数据类型,报错。
将NUMBER数据to_char转为字符串时,可以取出。详见下面部分代码。
即:

sprintf(sqlBuf,"SELECT to_char(CTRL_FLAG) FROM cct_business_ctrl where op_code='8000' and ctrl_no=10001 ");
求大神解释?
环境:
AIX Version 6.1! 
数据库:/oracle9i/app/oracle/product/9.2.0

部分代码如下:

OCIEnv* envhp; 		/*OCI environment handle*/
 	OCISvcCtx* svchp; 		/*OCI Service context handle*/
	char sqlBuf[INTER_SQLBUF_LEN];	
	int ctrl_flag=0;
	char sctrl_flag[2]; memset(sctrl_flag,0x0,sizeof(sctrl_flag));
	otl_nocommit_stream otl_sql_handle;
 	if(SQLEnvGet((dvoid *)context,&envhp)){
  	    sprintf(inter_pubinfo->ErrMsg,"get an OCI formatted environment handle from the primary connection Error[SQLEnvGet(0,&envhp)],Please Check.");
            return -1;
 	}

 	if(SQLSvcCtxGet((dvoid *)context,(text *) NULL,(ub4) 0,&svchp)){
            ...
            return -1;
 	}
	otl_connect otl_dbcon;
	memset(inter_pubinfo,0,sizeof(INTER_PUBINFO_TYPE));
	inter_pubinfo->otlcon=&otl_dbcon;
 	otl_connect::otl_initialize();
 	try{
  	    otl_dbcon.rlogon(envhp,svchp);
	    memset(sqlBuf,0,sizeof(sqlBuf));
	    /*sprintf(sqlBuf,"SELECT CTRL_FLAG FROM cct_business_ctrl where op_code='8000' and ctrl_no=10001 ");    取不出数据,注:CTRL_FLAG 是 NUMBER(1) 数据类型*/
	    sprintf(sqlBuf,"SELECT to_char(CTRL_FLAG) FROM cct_business_ctrl where op_code='8000' and ctrl_no=10001 ");    //可以取出数据
	    otl_sql_handle.open(1,sqlBuf,otl_dbcon);
	    otl_sql_handle>>sctrl_flag;
	    if(0 == otl_sql_handle.get_rpc()){
	        printf("取标示错误,请检查!");
	        otl_sql_handle.close();
               return -1;
            }
            otl_sql_handle.close();
            ctrl_flag = atoi(sctrl_flag);    
//......

展开
收起
爱吃鱼的程序员 2020-06-22 15:06:06 591 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    还是自问自答:

    本以为该 AIXVersion6.1!系统没有oracle11.2.0版本数据库。

    后同事告知有ORACLE11.2.0版本,因此修改makefile,使用11版本数据后,

    问题消失。

    自己找了个博文涉及到此:

    http://bbs.chinaunix.net/thread-3771530-1-1.html

    里面有段话:

    其中test_tab表,有3个字段,"createtabletest_tab(f1number,f2clob,f3clob)"
    有个问题就是,当查询前,如果charp[1024*1024*100];就会core
    但如果采用malloc方法,(被注释部分),就不会core了。

    但是也没有给出原因。只是提出了解决办法。

    2020-06-22 15:06:22
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
DTCC 2022大会集锦《云原生一站式数据库技术与实践》 立即下载
阿里云瑶池数据库精要2022版 立即下载
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载