I cannot understand the Oracle documentation. 🙁
Does anybody know how to fetch multiple rows of simple data from Oracle via OCI?
I currently use OCIDefineByPos to define single variables (I only need to do this for simple integers — SQLT_INT/4-byte ints) and then fetch a single row at a time with OCIStmtExecute/OCIStmtFetch2.
This is OK for small amounts of data but it takes around .5ms per row, so when reading a few ten thousand rows this is too slow.
I just don’t understand the documentation for OCIBindArrayOfStruct. How can I fetch a few thousand rows at a time?
You can use
OCIDefineArrayOfStructto support fetching arrays of records. You do this by passing the base of the array toOCIDefineByPos, and useOCIDefineArrayOfStructto tell Oracle about the size of the records (skip size). I believe that you then callOCIFetchtelling it to fetch the array size.An alternative is to set the statement attribute,
OCI_ATTR_PREFETCH_ROWS, before it is executed. This tells Oracle how many rows to fetch at a time, it defaults to 1. Using this approach, Oracle makes fewer round trips and buffers the rows for you.OCIBindArrayOfStructis used with DML statements. It works in a similar fashion toOCIDefineArrayOfStructexcept that it works with bind variables.You can find sample code on the Oracle website.