OceanBase Connector/ODBC supports the Call Function command. The syntax is as follows:
{call func_name()}
During execution, the Call Function command is converted to the following statement:
BEGIN
func_name()
END;
Here is an example:
ODBC_TEST(test_func_normal)
{
SQLRETURN ret = 0;
SQLLEN outLen = 0;
char *createpl = "create or replace function query_bench(str in varchar2) RETURN varchar2 IS\n"
" l_rst varchar2(100);\n"
"begin\n"
" l_rst:='1234455';\n"
" RETURN l_rst;\n"
"end query_bench;";
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 QUERY_BENCH(?)}";
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, buf2, 100, &inOut);
rcode = SQLExecute(Stmt);
CHECK_STMT_RC(Stmt, rcode);
printf("buf2=%s\n", buf1);
return OK;
}
