I am looking for a way to invoke an anonymous PLsql block through SOCI. Data transfer occurs through refcursor, which was previously created as a variable in the script:
variable rc refcursor
declare
v_obj_id number(4,0) := 1;
v_obj_def varchar(30);
v_obj_type number := 1;
begin
open :rc for
select v_obj_id, OBJ_DEF_ID
from MY_OBJECT_DEFS
where OBJECT_TYPE = v_obj_type;
end;
I need to read refcursor from my application to get the data. I tried to follow the procedure described above with the aid soci::statement, but it gave me an error: ORA-24333: zero iteration count. PLsql script works fine when executed in SqlPlus.
- How can I establish a relationship between a statement and refcursor rc? Should I use any other SOCI construct (other than instructions) for this purpose?
- I understand that in the above script; (for example, creating refcursor, ii) the anonymous PLsql block itself). I am not sure if several instructions can be named in one SOCI statement. Can this be confirmed?
. sSQL PLsql script:
dbConn.open("...");
int iObjId;
std::string iObjDefId;
soci::indicator ind_iObjId = soci::i_ok,
ind_iObjDefId = soci::i_ok;
soci::statement stmt(dbConn);
stmt.alloc();
stmt.prepare(sSQL);
stmt.exchange(soci::into(iObjId, ind_iObjId));
stmt.exchange(soci::into(iObjDefId, ind_iObjDefId));
stmt.define_and_bind();
stmt.execute(false);
while (stmt.fetch())
{
if (soci::i_ok == ind_iObjId)
std::cout << "Obj ID: " << iObjId << std::endl;
if (soci::i_ok == ind_iObjDefId)
std::cout << "Obj Def ID: " << iObjDefId << std::endl;
}
EDIT: Oracle 11g