简体   繁体   English

OCI要求选择语句

[英]OCI call for select statement

I have to write OCI code for a simple query like Select * from emp; 我必须为诸如Select * from emp;类的简单查询编写OCI代码Select * from emp;

Since I dont know how many rows will be returned I cannot preallocate my buffers So I define a void ** pointer while I associate my output buffers. 由于我不知道将返回多少行,因此无法预先分配缓冲区,因此在关联输出缓冲区时定义了void **指针。

The idea is to call the OCIStmtExecute with iters = 0 since 这个想法是用iters = 0来调用OCIStmtExecute ,因为

For SELECT statements, if iters is nonzero, then defines must have been done for the statement handle. 对于SELECT语句,如果iters非零,则必须已对语句句柄进行了定义。 The execution fetches iters rows into these predefined buffers and prefetches more rows depending upon the prefetch row count. 执行将迭代行提取到这些预定义的缓冲区中,并根据预取行数预取更多行。 If you do not know how many rows the SELECT statement will retrieve, set iters to zero. 如果您不知道SELECT语句将检索多少行,请将iters设置为零。

This function returns an error if iters=0 for non-SELECT statements. 如果非SELECT语句的iters = 0,则此函数返回错误。

After that I plan to do OCIAttrGet(OCI_ATTR_ROW_COUNT) to get the numbers to rows returned by the select statement and then allocate memory for the output buffers and then call the OCIStmtFetch by specifying the numbers of rows hence returned. 之后,我计划执行OCIAttrGet(OCI_ATTR_ROW_COUNT)将数字获取到由select语句返回的行,然后为输出缓冲区分配内存,然后通过指定因此返回的行数来调用OCIStmtFetch。

But the row count that I get is 0 every time even though there is data returned by the table. 但是,即使有表返回的数据,我每次获得的行计数也是0。

Is there some flaw with my approach? 我的方法是否有缺陷? Could you point out the flaw 你能指出缺陷吗

You simply need to allocate space for one row, then call OCIStmtFetch2() repeatedly until you reach the end of the result set (which will give error code 1403). 您只需要为一行分配空间,然后重复调用OCIStmtFetch2()直到到达结果集的末尾(这将给出错误代码1403)。 The prefetch happens into a buffer maintained by OCI itself, transparently to you, so this method is not inefficient. 预取发生在OCI本身维护的缓冲区中,对您是透明的,因此此方法效率不高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM