- 论坛徽章:
- 0
|
//#include <iostream.h>;
#include <stdlib.h>;
#include <stdio.h>;
#include "e:\oracle\ora81\precomp\public\sqlca.h"
void error_proc();
void main()
{
char uname[] = "westnetwork/westnetwork";
char dname[] = "YX";
//EXEC SQL BEGIN DECLARE SECTION;
char RoadName[20];
char RoadNo[20];
//EXEC SQL END DECLARE SECTION;
//异常
EXEC SQL WHENEVER SQLERROR DO error_proc();
//连接
EXEC SQL CONNECT :uname USING :dname;
//EXEC SQL WHENEVER NOT FOUND DO CONTINUE;
//Select、Insert、Update等SQL处理
//EXEC SQL SELECT roadno,roadname INTO :RoadNo,:RoadName FROM road
//WHERE roadno=105;
//printf("\n 路段编码:%-20s 路段名称: %-20s\n",RoadNo,RoadName);
EXEC SQL DECLARE c1 CURSOR FOR
SELECT ROADNO,ROADNAME FROM ROAD;
EXEC SQL OPEN c1;
do
{
EXEC SQL FETCH c1 INTO :RoadNo,:RoadName;
if (sqlca.sqlcode=1403) break;
printf("\n 路段编码:%-20s 路段名称: %-20s\n",RoadNo,RoadName);
//getch();
}while (1);
EXEC SQL CLOSE c1;
//提交并释放连接
EXEC SQL COMMIT WORK RELEASE;
exit(0);
}
void error_proc()
{
printf("\n%.*s!",sqlca.sqlerrm.sqlerrml,sqlca.sqlerrm.sqlerrmc);
exit(-1);
}
上面代码不用游标可以,如何用游标,问题在哪? |
|