How to get the return value of an Oracle function?
Posted: Mon 04 Mar 2013 14:17
In a package 'UTILS' I have the function:
FUNCTION TestF(p_Name IN VARCHAR2) RETURN INTEGER;
In C++ Builder I call the function by:
OraQuery1->SQL->Add(L"DECLARE");
OraQuery1->SQL->Add(L" v_Res INTEGER;");
OraQuery1->SQL->Add(L"BEGIN");
OraQuery1->SQL->Add(L"v_Res := UTILS.TestF(:p_Name);");
OraQuery1->SQL->Add(L"END;");
OraQuery1->ParamByName(L"p_Name")->AsString = L"TestName";
OraQuery1->Execute();
All is OK. The function is executed correctly. But how to get the return parameter of the function? My test was:
OraQuery1->SQL->Add(L"BEGIN");
OraQuery1->SQL->Add(L":p_Res := UTILS.TestF(:p_Name);");
OraQuery1->SQL->Add(L"END;");
OraQuery1->ParamByName(L"p_Name")->AsString = L"TestName";
OraQuery1->Execute();
int res = OraQuery1->ParamByName(L"p_Res")->AsInteger;
But this fails with error EOraError::ORA-06502 ( numeric or value error: character string buffer too small)
I think I have to declare the return value before. But how to do?
Markus
FUNCTION TestF(p_Name IN VARCHAR2) RETURN INTEGER;
In C++ Builder I call the function by:
OraQuery1->SQL->Add(L"DECLARE");
OraQuery1->SQL->Add(L" v_Res INTEGER;");
OraQuery1->SQL->Add(L"BEGIN");
OraQuery1->SQL->Add(L"v_Res := UTILS.TestF(:p_Name);");
OraQuery1->SQL->Add(L"END;");
OraQuery1->ParamByName(L"p_Name")->AsString = L"TestName";
OraQuery1->Execute();
All is OK. The function is executed correctly. But how to get the return parameter of the function? My test was:
OraQuery1->SQL->Add(L"BEGIN");
OraQuery1->SQL->Add(L":p_Res := UTILS.TestF(:p_Name);");
OraQuery1->SQL->Add(L"END;");
OraQuery1->ParamByName(L"p_Name")->AsString = L"TestName";
OraQuery1->Execute();
int res = OraQuery1->ParamByName(L"p_Res")->AsInteger;
But this fails with error EOraError::ORA-06502 ( numeric or value error: character string buffer too small)
I think I have to declare the return value before. But how to do?
Markus