OPEN CURSOR得时候,能马上得到rowcount得值吗?怎么是零?

[复制链接]
查看11 | 回复4 | 2007-9-26 18:42:10 | 显示全部楼层 |阅读模式
OPEN CURSOR得时候,能马上得到rowcount得值吗?怎么是零?
回复

使用道具 举报

千问 | 2007-9-26 18:42:10 | 显示全部楼层
Counting Rows Affected by FORALL Iterations with the %BULK_ROWCOUNT Attribute
To process SQL data manipulation statements, the SQL engine opens an implicit cursor named SQL. This cursor's scalar attributes, %FOUND, %ISOPEN, %NOTFOUND, and %ROWCOUNT, return useful information about the most recently executed SQL data manipulation statement.
The SQL cursor has one composite attribute, %BULK_ROWCOUNT, designed for use with the FORALL statement. This attribute has the semantics of an index-by table. Its ith element stores the number of rows processed by the ith execution of an INSERT, UPDATE or DELETE statement. If the ith execution affects no rows, %BULK_ROWCOUNT(i) returns zero.
...........
就是说 %BULK_ROWCOUNT(i)
回复

使用道具 举报

千问 | 2007-9-26 18:42:10 | 显示全部楼层
从下面的测试可以知道cursor%rowcount是随着fetch增加的:
cjf@CJF>select deptno from dept;
DEPTNO
----------
30
40
10
20
cjf@CJF>set serveroutput on;
cjf@CJF>create or replace procedure cursor_rc
2 is
3 v_dept number;
4 cursor cl1 is select deptno from dept;
5begin
6open cl1;
7dbms_output.put_line(cl1%rowcount);
8loop
9fetch cl1 into v_dept;
10exit when cl1%notfound;
11
12dbms_output.put_line(cl1%rowcount);
13end loop;
14close cl1;
15end cursor_rc;
16/
过程已创建。
cjf@CJF>exec cursor_rc;
0
1
2
3
4
PL/SQL 过程已成功完成。
cjf@CJF>
回复

使用道具 举报

千问 | 2007-9-26 18:42:10 | 显示全部楼层
最初由 yzm2008 发布
[B]OPEN CURSOR得时候,能马上得到rowcount得值吗?怎么是零? [/B]

所以OPEN CURSOR得时候,能马上得到rowcount的值,只不过此时此值为0而已。
回复

使用道具 举报

千问 | 2007-9-26 18:42:10 | 显示全部楼层
rowcount是你已经fetch的记录的条数, 而不是系统可能返回的记录的总条数..
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行