当前位置: 技术问答>linux和unix
请各位高手看看这段PRO*C程序为什么编译不能通过?
来源: 互联网 发布时间:2015-07-07
本文导语: #include #define DB_NOTFOUND 1403 EXEC SQL INCLUDE SQLCA; EXEC SQL BEGIN DECLARE SECTION; typedef struct { char user_name[100]; char gender[4]; int age; int grade; char address[300]; int id; } rec_def; ...
#include
#define DB_NOTFOUND 1403
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
typedef struct
{ char user_name[100];
char gender[4];
int age;
int grade;
char address[300];
int id;
} rec_def;
char user_name[20];
char password[20];
VARCHAR sql_statement[300];
int u_id;
EXEC SQL END DECLARE SECTION;
void select_cond();
void main()
{
/* int user;*/
rec_def flag,*p_flag;
p_flag = &flag;
strcpy(user_name,"ops$pbora");/*用户名ops$pbora*/
strcpy(password,"pbora");/*密码pbora*/
EXEC SQL CONNECT :user_name IDENTIFIED BY :password;/*登录数据库*/
if(sqlca.sqlcode user_name,p_flag->gender,p_flag->age,
p_flag->grade,p_flag->address,p_flag->id;
if(sqlca.sqlcode !=0)
{
printf("已到表尾了!n");
return;
}
printf("----------------------n");
printf("姓名:%s",p_flag->user_name);
printf("性别:%s",p_flag->gender);
printf("年龄:%d",p_flag->grade);
printf("年级:%d",p_flag->grade);
printf("地址:%s",p_flag->address);
printf("号码:%dn",p_flag->id);
}while(sqlca.sqlcode != DB_NOTFOUND);
EXEC SQL CLOSE my_cur;
EXEC SQL COMMIT WORK RELEASE;
if(sqlca.sqlcode !=0 )
{
printf("关闭数据库失败!n");
return;
}
}
void select_cond()
{
printf("请输入ID:");
scanf("%d",u_id);
printf("n");
strcat(sql_statement.arr,u_id);
}
#define DB_NOTFOUND 1403
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
typedef struct
{ char user_name[100];
char gender[4];
int age;
int grade;
char address[300];
int id;
} rec_def;
char user_name[20];
char password[20];
VARCHAR sql_statement[300];
int u_id;
EXEC SQL END DECLARE SECTION;
void select_cond();
void main()
{
/* int user;*/
rec_def flag,*p_flag;
p_flag = &flag;
strcpy(user_name,"ops$pbora");/*用户名ops$pbora*/
strcpy(password,"pbora");/*密码pbora*/
EXEC SQL CONNECT :user_name IDENTIFIED BY :password;/*登录数据库*/
if(sqlca.sqlcode user_name,p_flag->gender,p_flag->age,
p_flag->grade,p_flag->address,p_flag->id;
if(sqlca.sqlcode !=0)
{
printf("已到表尾了!n");
return;
}
printf("----------------------n");
printf("姓名:%s",p_flag->user_name);
printf("性别:%s",p_flag->gender);
printf("年龄:%d",p_flag->grade);
printf("年级:%d",p_flag->grade);
printf("地址:%s",p_flag->address);
printf("号码:%dn",p_flag->id);
}while(sqlca.sqlcode != DB_NOTFOUND);
EXEC SQL CLOSE my_cur;
EXEC SQL COMMIT WORK RELEASE;
if(sqlca.sqlcode !=0 )
{
printf("关闭数据库失败!n");
return;
}
}
void select_cond()
{
printf("请输入ID:");
scanf("%d",u_id);
printf("n");
strcat(sql_statement.arr,u_id);
}
|
语法错误:
EXEC SQL FETCH my_cur INTO :p_flag->user_name,p_flag->gender,。。。
语句中,每个变量前面都要有“:”
应该是:
EXEC SQL FETCH my_cur INTO :p_flag->user_name,:p_flag->gender,:p_flag->age,:p_flag->grade,:p_flag->address,:p_flag->id;
EXEC SQL FETCH my_cur INTO :p_flag->user_name,p_flag->gender,。。。
语句中,每个变量前面都要有“:”
应该是:
EXEC SQL FETCH my_cur INTO :p_flag->user_name,:p_flag->gender,:p_flag->age,:p_flag->grade,:p_flag->address,:p_flag->id;
|
Gemini77(双子星) 说得对.
sqlca小写没错.
sqlca小写没错.
|
我给你编译了一下,首先游标的定位不能多个定位:
do
{
EXEC SQL FETCH my_cur INTO :p_flag->user_name,p_flag->gender,p_flag->age,
p_flag->grade,p_flag->address,p_flag->id;
你把它改成 EXEC SQL FETCH my_cur INTO :p_flag->user_name;一个一个地取值吧。
另外:
void select_cond()
scanf("%d",&u_id);
这样就可以通过了