我正在尝试在Pro * C下面执行代码并且编译成功。当我执行程序时,代码中的SELECT
语句失败,sqlca.sqlcode
为-1012
。我找不到这个错误的含义。有人可以帮我解决我在这方面做错了什么。
#include<stdio.h>
#include<stdlib.h>
#include<sqlca.h>
#define SQLCA_STORAGE_CLASS
// EXEC SQL INCLUDE sqlca.h;
void sqlerror()
{
printf("In error\n");
printf("SQLCODE:<%d>\n",sqlca.sqlcode);
EXEC SQL ROLLBACK RELEASE;
exit(1);
}
void main()
{
EXEC SQL BEGIN DECLARE SECTION;
char *username="dummy";
char *pwd="dummy";
char *dbname="dbname";
int counter;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL CONNECT :username IDENTIFIED BY :pwd at :dbname;
if(sqlca.sqlcode == 0)
{
printf("connected\n");
}
printf("Before SQLCODE:<%d>\n",sqlca.sqlcode);
EXEC SQL SELECT count(1)
into :counter
from TEST
where rownum <3;
printf("SQLCODE:<%d>\n",sqlca.sqlcode);
if(sqlca.sqlcode == 0)
{
printf("connected2\n");
}
printf("Account number is %d",counter);
EXEC SQL COMMIT RELEASE;
if(sqlca.sqlcode == 0)
{
printf("connection released\n");
}
}
编译完成后,当我执行程序时,我得到了输出
connected
Before SQLCODE:<0>
In error
SQLCODE:<-1012>
下面是编译器选项
proc iname=sample.pc include=/dbvolume/oracle/product/11.2.0_client_1/rdbms/public sqlcheck=semantics userid=dummy/dummy
gcc -o sample sample.c -I/dbvolume/oracle/product/11.2.0_client_1/precomp/public/ -L$ORACLE_HOME/lib -lclntsh