Pro * C 简单例子

#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指定需要的库文件路径

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值