#include <stdio.h>
exec sql begin declare section;
char userid[11]="hr/oracle";
char std_name[10];
int std_number;
int dept_number;
exec sql end declare section;
char temp[3];
void sql_error();
#include <sqlca.h>
main()
{
std_number=060415;
exec sql whenever sqlerror do sql_error("oracle error");
exec sql connect :userid;
printf("connect./n");
exec sql declare gxj_cursor cursor for
select last_name
from employees
where employee_id=:dept_number;
printf("employee number?");
gets(temp);
dept_number=atoi(temp);
exec sql open gxj_cursor;
printf("student name/n");
printf("----------------------------/n");
exec sql whenever not found do break;
while(1)
{
exec sql fetch gxj_cursor into :std_name;
printf("%s/n",std_name);
}
exec sql close gxj_cursor;
exec sql commit work release;
exit(0);
}
void
sql_error(msg)
char * msg;
{
char buf[500];
int buflen,msglen;
exec sql whenever sqlerror continue;
exec sql rollback work release;
buflen=sizeof(buf);
sqlglm(buf,&buflen,&msglen);
printf("%s/n",msg);
printf("%*.s/n",msglen,buf);
exit(1);
}
1. edit a pc file, for example test.pc
2. proc test.pc
3. gcc test.c -I/u01/app/oracle/product/10.2.0/db_1/precomp/public -L/u01/app/oracle/product/10.2.0/db_1/lib -lclntsh 其中-I指定include路径, -L指定需要的库文件路径