我是先用这个语句在oracle环境下创建的表
create table dept (deptno number(2) constraint pk_dept primary key, dname varchar2(14) , loc varchar2(13) ) ;
然后插入了些数据
insert into dept values (10, 'accounting', 'new york');insert into dept values (20, 'research', 'dallas');insert into dept values (30, 'sales', 'chicago');insert into dept values (40, 'operations', 'boston');
用select命令可以读取到,但是用下面代码时却读取不到任何东西,求大侠帮忙鉴定一下:
[code=C/C++][/code]#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlca.h>
int main(int argc,char* argv[])
{
EXEC SQL BEGIN DECLARE SECTION;
char *uid = "system/abcdef@myhost/orcl";
long userid=0;
char username[51]="";
EXEC SQL VAR username IS STRING(51);
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT :uid;
if(sqlca.sqlcode == 0)
printf("connect sucess!\n");
else
printf("connect fail!\n");
EXEC SQL DECLARE cur_user CURSOR FOR SELECT DEPTNO, DNAME FROM DEPT;
EXEC SQL OPEN cur_user;
while(1){
userid=0;
strcpy(username,"");
EXEC SQL FETCH cur_user INTO :userid, :username;
if( sqlca.sqlcode == 1403) break;
printf("userid=%ld,username=%s\n",userid,username);
}
EXEC SQL CLOSE cur_user;
// EXEC SQL COMMIT WORK RELEASE;
EXEC SQL ROLLBACK WORK RELEASE;
return 0;
}
------解决方案--------------------
不懂proc,帮楼主顶下。
------解决方案--------------------
不解,希望有大侠帮你快点解决。。。
------解决方案--------------------
commit了没有?
另外,游标打开是否成功没有判断
------解决方案--------------------
- SQL code
--看下有没有,没有就说明你不是在system用户下建立的,切换到system用户下建立表或者在system用户下建个同义词select * from system.dept;