#include <stdio.h>
typedef char asciz[20];
EXEC SQL BEGIN DECLARE SECTION;
/* Define type for null-terminated strings */
EXEC SQL TYPE asciz IS STRING(20) REFERENCE;
asciz username;
asciz password;
asciz emp_name;
short ind;
float salary;
float commission;
EXEC SQL END DECLARE SECTION;
EXEC SQL INCLUDE sqlca;

void sqlerror(); /* handles unrecoverable errors */

main()
{
/* Log on to ORACLE */
strcpy(username, "SCOTT");
strcpy(password, "TIGER");

/**
** ORA_NLS 는 ORACLE 7.2 에서만 필요 함.
**/
putenv("ORACLE_HOME=/oracle/oracle");
putenv("ORACLE_SID=RC722");
putenv("NLS_LANG=American_America.ko16ksc5601");
putenv("ORA_NLS=/oracle/oracle/ocommon/nls/admin/data");

EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf("\nConnected to ORACLE as user: %s\n", username);
EXEC SQL DECLARE salespeople CURSOR FOR
SELECT ENAME, SAL, COMM
FROM EMP
WHERE JOB LIKE 'SALES%';
EXEC SQL OPEN salespeople;
for ( ; ; )
{
EXEC SQL FETCH salespeople
INTO :emp_name, :salary, :commission:ind;
if (sqlca.sqlcode == 1403) break;
if (sqlca.sqlcode ==0) {
printf("%-11s%9.2f%13.2f\n", emp_name, salary, commission);
}
}
EXEC SQL CLOSE salespeople;
printf("\nHave a good day.\n");
EXEC SQL COMMIT WORK RELEASE;
exit(0);
}

void sqlerror()
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf("\nORACLE error detected:\n");
printf("\n% .70s \n", sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK RELEASE;
exit(1);
}

, .