#include <stdio.h>
#include <sqlca.h>

void sqlerror();

EXEC SQL BEGIN DECLARE SECTION;
char *connstr = "scott/tiger";
char db_ename[30];
intdb_deptno;
EXEC SQL END DECLARE SECTION;

void main() {
EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL WHENEVER SQLWARNING CONTINUE;
EXEC SQL CONNECT :connstr;

EXEC SQL DECLARE emp_cursor CURSOR FOR
SELECT ENAME, DEPTNO
FROM EMP;

EXEC SQL OPEN emp_cursor;

EXEC SQL WHENEVER NOT FOUND DO break;
for (;;) {
EXEC SQL FETCH emp_cursor INTO :db_ename, :db_deptno;
printf("\t%s\t%i\n", db_ename, db_deptno);
}

EXEC SQL CLOSE emp_cursor;
EXEC SQL COMMIT WORK RELEASE;
return;
}

void sqlerror() {
printf("Stop Error:\t%25i\n", sqlca.sqlcode);
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL ROLLBACK WORK RELEASE;
return;
}

원본 http://blog.naver.com/julymorning4/100024943004

, .