- 论坛徽章:
- 15
|
原帖由 pingping09 于 2009-7-20 11:43 发表 ![]()
我想用c语言直接调用存储过程,因为还需要使用存储过程的返回值,所以比较麻烦。
数据库是oracle 10
网上搜了一下,也没找到相关例子
哪位大侠帮我啊
这是一个sqlora接口的例子,内部是OCI。
- int call_plsql(sqlo_db_handle_t dbh)
- {
- double ip1;
- int ip2;
- char op[80];
- sqlo_stmt_handle_t sth = SQLO_STH_INIT;
- /* the stored procecdure call */
- char * stmt =
- "BEGIN\n"
- " EX9(:ip1, :ip2, :op);\n"
- "END;\n";
- ip1 = 1.5;
- ip2 = 20;
- /* parse the statement */
- if ( 0 <= (sth = sqlo_prepare(dbh, stmt))) {
- /* bind all variables */
- if (SQLO_SUCCESS !=
- (sqlo_bind_by_name(sth, ":ip1", SQLOT_FLT, &ip1, sizeof(ip1), 0, 0) ||
- sqlo_bind_by_name(sth, ":ip2", SQLOT_INT, &ip2, sizeof(ip2), 0, 0) ||
- sqlo_bind_by_name(sth, ":op", SQLOT_STR, &op, sizeof(op), 0, 0)
- )) {
-
- error_exit(dbh, "sqlo_bind_by_name");
- } else {
- /* execute the call */
- if (SQLO_SUCCESS != sqlo_execute(sth, 1))
- error_exit(dbh, "sqlo_execute");
- }
- /* print the result */
- if (atof(op) != (ip1 + ip2))
- printf("Stored procudure returned wrong result %s, expected %6.2f\n",
- op, (ip1 + ip2));
- if (SQLO_SUCCESS != sqlo_close(sth))
- error_exit(dbh, "sqlo_execute");
- } else {
- error_exit(dbh, "sqlo_prepare");
- }
- return 1;
- }
复制代码
[ 本帖最后由 yulihua49 于 2009-7-20 12:54 编辑 ] |
|