各位大侠,我在IBM AIX5.3操作系统,ORACLE 9i下,一个PROC的程序, 在执行SELECT时偶尔报ORA-01036错,偶尔又正常,实在找不到什么原因,请大家帮帮忙啊~~急啊
源代码如下:
int SelectByID(TB_MID_LEDGER *ptb_mid_ledger,int iOpenFlag, char *s_paper_id)
{
int ret=FOK;
char sTemp[256]="";
char sTemp2[256]="";
char sErrMsg[512]="";
char szModuleName []="SelectByID";
EXEC SQL BEGIN DECLARE SECTION;
TB_MID_LEDGER tb_mid_ledger; /*一个同数据表字段一致的结构变量*/
char sPaperId [19];
char sPaperId2 [19];
char paper_id [19];
char paper_type_cd [3 ];
char acc_flag [25];
EXEC SQL END DECLARE SECTION;
printf("[%s] start...",szModuleName);
memset(&tb_mid_ledger ,0,sizeof(tb_mid_ledger));
tb_mid_ledger.acc_flag[0]='1' ;
strcpy(tb_mid_ledger.paper_type_cd,"01");
strcpy(tb_mid_ledger.paper_id,s_paper_id); /*这里暂时只用18位号码*/
memset(sPaperId,0,sizeof(sPaperId));
memset(sPaperId2,0,sizeof(sPaperId2));
memcpy(sPaperId,tb_mid_ledger.paper_id, 6 );
memcpy(sPaperId+6,tb_mid_ledger.paper_id+8, 9 );
memcpy(sPaperId2,tb_mid_ledger.paper_id,18);
if(sPaperId2[17]=='X')
{
sPaperId2[17]='x';
}
else if (sPaperId2[17]=='x')
{
sPaperId2[17]='X';
}
memset(paper_id ,0,sizeof(paper_id ));
memset(paper_type_cd,0,sizeof(paper_type_cd));
memset(acc_flag ,0,sizeof(acc_flag ));
strcpy(paper_id ,tb_mid_ledger.paper_id );
strcpy(paper_type_cd,tb_mid_ledger.paper_type_cd);
strcpy(acc_flag ,tb_mid_ledger.acc_flag );
printf("paper_type_cd=[%s],paper_id=[%s]/[%s]/[%s],acc_flag=[%s]",
paper_type_cd ,paper_id, sPaperId,sPaperId2,acc_flag);
EXEC SQL SELECT * INTO :tb_mid_ledger /*这条查询语句报ORA-01036错*/
FROM tb_mid_ledger
WHERE ( paper_id = :paper_id
OR paper_id = :sPaperId2 )
AND paper_type_cd = :paper_type_cd
AND substr(acc_flag,1,1) = :acc_flag
AND card_hold_fg = '00' ;
return 0;
}
打印出来的日志如下:
"paper_type_cd=[01],paper_id=[440127194801065310]/[440127480106531]/[440127194801065310],acc_flag=[1]"
------解决方案--------------------
ORA-01036 illegal variable name/number
Cause: Unable to find bind context on user side.
Action: Make sure that the variable being bound is in the SQL statement
------解决方案--------------------
------解决方案--------------------
手工调试一下PROC,跟踪最近表结构是否被改过。
另外,千万不要用 select * ,这是PROC编程的基本原则之一。 否则,到时候会死的很惨,大批量出错 + 急着上报 + 领导视察 的情况,好好想想吧。