oracle的pro*c语法 调用函数包含入参 接受返回值的代码用例
时间: 2023-02-02 14:41:35 浏览: 108
以下是 Oracle Pro*C 调用函数,包含入参和接受返回值的代码示例:
```
#include <stdio.h>
#include <sqlca.h>
#include <oraca.h>
#include <oci.h>
void check_err(OCIError *errhp)
{
sb4 errcode = 0;
text errbuf[512];
memset(errbuf, 0, sizeof(errbuf));
OCIErrorGet((dvoid *)errhp, (ub4)1, (text *)NULL, &errcode,
errbuf, (ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
printf("Error - %s\n", errbuf);
}
int main()
{
/* 初始化环境 */
OCIEnv *envhp;
OCIError *errhp;
OCIServer *srvhp;
OCISvcCtx *svchp;
OCISession *authp;
OCIStmt *stmthp;
sword status;
status = OCIEnvCreate((OCIEnv **)&envhp, OCI_DEFAULT, (dvoid *)0,
(dvoid * (*)(dvoid *, size_t))0,
(dvoid * (*)(dvoid *, dvoid *, size_t))0,
(void (*)(dvoid *, dvoid *))0, (size_t)0, (dvoid **)0);
if (status != OCI_SUCCESS)
{
printf("OCIEnvCreate failed\n");
return -1;
}
status = OCIHandleAlloc((dvoid *)envhp, (dvoid **)&errhp, OCI_HTYPE_ERROR,
(size_t)0, (dvoid **)0);
if (status != OCI_SUCCESS)
{
printf("OCIHandleAlloc (error handle) failed\n");
return -1;
}
/* 连接数据库 */
status = OCIHandleAlloc((dvoid *)envhp, (dvoid **)&srvhp, OCI_HTYPE_SERVER,
(size_t)0, (dvoid **)0);
if (status != OCI_SUCCESS)
{
printf("OCIHandleAlloc (server handle) failed\n");
return -1;
}
status = OCIServerAttach(srvhp, errhp, (text *)"", strlen(""), 0);
if (status != OCI_SUCCESS)
{
check_err(errhp);
return -1;
}
status = OCIHandleAlloc((dvoid *)envhp, (dvoid **)&svchp, OCI_HTYPE_SVCCTX,
(size_t)0, (dvoid
阅读全文