Call an Oracle stored procedure via OCI and return the results with an out ref cursor in C++ -
i call oracle stored procedure c++ using oci interface , iterate on results using out sys_ref_cursor parameter procedure. i'm new oci might missing simple. of code taken here: https://community.oracle.com/thread/507765?start=0&tstart=0
my stored procedure is:
create or replace procedure fxt_test_call(cresults out sys_refcursor) stestquery varchar2(4000); begin stestquery := ' select set_nam, cc_type fxt_con_rules'; open cresults stestquery; end fxt_test_call;
and c++ code snippet is:
ocierror* pocierror; int answer; ocistmt* pocistatement; char* sqlchararray = "begin fxt_test_call; end;"; char set_nam[40]; char cc_type[40]; ocienv* g_pocienvironment = null; ociserver* g_pociserver = null; ocisession* g_pocisession = null; ocisvcctx* g_pociservicecontext = null; sb2* pindicator=0; sb2* pindicator2=0; sb2* pindicator3=0; ocidefine* pocidefine; ocidefine* pocidefine2; ocibind* pbind; ocistmt* cursor; answer = ocihandlealloc(g_pocienvironment, (void **)(&pocistatement), oci_htype_stmt, 0, null); answer = ocistmtprepare(pocistatement, pocierror, (unsigned char *)sqlchararray, strlen(sqlchararray),oci_ntv_syntax, oci_default); answer = ocihandlealloc(g_pocienvironment, (void **)(&cursor), oci_htype_stmt, 0, null); // error "ora-01036: illegal variable name/number" after line answer = ocibindbypos(pocistatement,&pbind, pocierror, 1, &cursor, 0,sqlt_rset, pindicator2, 0,null, 0,0,oci_default); answer = ocistmtexecute(g_pociservicecontext, pocistatement, pocierror, 1, 0, null, null, oci_commit_on_success); answer = ocidefinebypos(cursor,&pocidefine, pocierror,1,set_nam,40, sqlt_str,pindicator, 0, 0,oci_default); answer = ocidefinebypos(cursor,&pocidefine2, pocierror,2,cc_type,40, sqlt_str,pindicator3, 0, 0,oci_default); // loop debug see if set_nam , cc_type being populated int blah = 0; while ((answer = ocistmtfetch(cursor,pocierror, 1,oci_fetch_next,oci_default)) == 0) { blah++; }
the stored procedure difficult change prefer amend code. oracle version is: oracle database 11g enterprise edition release 11.2.0.4.0 in advance.
you've set:
sqlchararray = "begin fxt_test_call; end;"
which has no bind parameters; you're trying set one, hence error, , procedure definition requires one. need call as:
sqlchararray = "begin fxt_test_call(:1); end;"
Comments
Post a Comment