OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Connector/ODBC

V2.0.7
  • Overview
  • Driver installation and configuration
    • Prepare for the installation
    • Install and configure OceanBase Connector/ODBC for Linux
    • Install and configure the OceanBase Connector/ODBC driver for Windows
  • User guide
    • Basic operations
    • Enable the logging feature
    • Obtain the REF CURSOR data type
  • Reference information
    • OceanBase Connector/ODBC API functions
    • OceanBase Connector/ODBC data types
    • OceanBase Connector/ODBC error codes
  • FAQ
    • Query timeout
    • Chinese garbled characters
  • Release
    • V2.0
      • OceanBase Connector/ODBC V2.0.7
      • OceanBase Connector/ODBC V2.0.6

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Connector/ODBC
  3. V2.0.7

Obtain the REF CURSOR data type

Last Updated:2026-09-04 08:24:40

OceanBase Connector/ODBC supports the REF CURSOR data type in Oracle mode to achieve cursor functionality.

The sys_refcursor field in the following example indicates that the output data type is the REF CURSOR data type.

ODBC_TEST(test_proc_cursor)
{
  SQLRETURN ret = 0;
  SQLLEN outLen = 0;
  char *createpl = "create or replace procedure Proc_Test(PO_CURSOR out sys_refcursor, S_CUR out sys_refcursor, sss out varchar2)\n"
    "is\n"
    "begin\n"
    "  sss:='111111';\n"
    "  OPEN PO_CURSOR FOR select '123',32,'dfab' from dual;\n"
    "  OPEN S_CUR FOR select 12,23,45,44 from dual;\n"
    "end Proc_Test;";

  CHECK_STMT_RC(Stmt, ret = SQLPrepare(Stmt, (SQLCHAR*)createpl, (SQLINTEGER)strlen((char*)createpl)));
  CHECK_STMT_RC(Stmt, ret = SQLExecute(Stmt));
  CHECK_STMT_RC(Stmt, ret = SQLFreeStmt(Stmt, SQL_CLOSE));
  SQLEndTran(SQL_HANDLE_DBC, Connection, SQL_COMMIT);

  SQLRETURN rcode;
  char *pCall = (char*)"{ call PROC_TEST(?,?,?)}";
  char buf1[100] = { 0 };
  char buf2[100] = { 0 };
  SQLLEN inOut = SQL_NTS;


  rcode = SQLPrepare(Stmt, (SQLCHAR*)pCall, strlen(pCall));
  CHECK_STMT_RC(Stmt, rcode);
  rcode = SQLBindParameter(Stmt, 1, SQL_PARAM_OUTPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, buf1, 100, &inOut);
  rcode = SQLBindParameter(Stmt, 2, SQL_PARAM_OUTPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, buf1, 100, &inOut);
  rcode = SQLBindParameter(Stmt, 3, SQL_PARAM_OUTPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, buf2, 100, &inOut);
  rcode = SQLExecute(Stmt);
  CHECK_STMT_RC(Stmt, rcode);
  printf("buf2=%s\n", buf2);

  char c1[100] = { 0 };
  char c2[100] = { 0 };
  double d1 = 0, d2= 0, d3=0, d4=0;
  rcode = SQLBindCol(Stmt, 1, SQL_C_CHAR, &c1, 100, NULL);
  rcode = SQLBindCol(Stmt, 2, SQL_C_DOUBLE, &d2, 8, NULL);
  rcode = SQLBindCol(Stmt, 3, SQL_C_CHAR, &c2, 100, NULL);
  rcode = SQLBindCol(Stmt, 4, SQL_C_DOUBLE, &d4, 8, NULL);
  CHECK_STMT_RC(Stmt, rcode = SQLFetch(Stmt));
  printf("%s,%d,%s,%d\n", c1, (int)d2, c2, (int)d4);
  rcode = SQLFetch(Stmt);
  is_num(rcode, 100);

  rcode = SQLMoreResults(Stmt);
  CHECK_STMT_RC(Stmt, rcode);
  rcode = SQLBindCol(Stmt, 1, SQL_C_DOUBLE, &d1, 8, NULL);
  rcode = SQLBindCol(Stmt, 2, SQL_C_DOUBLE, &d2, 8, NULL);
  rcode = SQLBindCol(Stmt, 3, SQL_C_DOUBLE, &d3, 8, NULL);
  rcode = SQLBindCol(Stmt, 4, SQL_C_DOUBLE, &d4, 8, NULL);
  CHECK_STMT_RC(Stmt, rcode = SQLFetch(Stmt));
  printf("%d,%d,%d,%d\n", (int)d1, (int)d2, (int)d3, (int)d4);
  rcode = SQLFetch(Stmt);
  is_num(rcode, 100);

  rcode = SQLMoreResults(Stmt); //return SQL_NO_DATA;
  is_num(rcode, 100);

  CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));
  return OK;
}

Previous topic

Enable the logging feature
Last

Next topic

OceanBase Connector/ODBC API functions
Next