- 论坛徽章:
- 0
|
本帖最后由 广西邮储银行 于 2011-07-23 23:57 编辑
这是一个insert的范例
[hwt@localhost xt8]$ cat xt8.pc
#include <stdio.h>
EXEC SQL INCLUDE sqlca;
void sqlerror();
int main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
char username[10];
char password[10];
char sid[10];
//char *uid="scott/scott@testdb";
int deptno=10;
char dname[20];
char loc[20];
EXEC SQL END DECLARE SECTION;
strcpy(username,"scott");
strcpy(password,"scott");
strcpy(sid,"testdb");
strcpy(dname,"fred");
strcpy(loc,"nann");
EXEC SQL WHENEVER SQLERROR DO sqlerror();//下面语句有报错就进入错误处理函数
EXEC SQL CONNECT :username
IDENTIFIED BY :password
USING :sid;
//EXEC SQL CONNECT :uid;
EXEC SQL INSERT INTO dept VALUES(:deptno,:dname,:loc);
EXEC SQL COMMIT WORK RELEASE;
exit(0);
}
void sqlerror() //自定义的错误处理函数
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
fprintf(stderr,"%d\n%-70s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
/*sqlca.sqlcode错误码*/
/*sqlca.sqlerrm.sqlerrmc错误信息*/
EXEC SQL ROLLBACK WORK RELEASE;
exit(1);
}
[hwt@localhost xt8]$ proc iname=xt8.pc oname=xt8.c
Pro*C/C++: Release 10.2.0.1.0 - Production on 星期二 4月 19 23:05:28 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
系统默认选项值取自于: /opt/app/oracle/product/10.2.0/db_1/precomp/admin/pcscfg.cfg
[hwt@localhost xt8]$ cc -I${ORACLE_HOME}/precomp/public xt8.c -o xt8 -L${ORACLE_HOME}/lib -lclntsh |
|