使用cusor%rowcount 1 declare 2 n number; 3 cursor c1 is select 1 from a016; 4 begin 5 open c1; 6 loop 7 fetch c1 into n; 8 exit when c1%notfound; 9 end loop; 10 n:=c1%rowcount; 11 dbms_output.put_line(n); 12 close c1; 13 dbms_output.put_line(n); 14* end;
楼上的没有看清题目.看来真是没有办法了.ORACLE的帮助说: "Rows in the result set are not retrieved when the OPEN statement is executed. Rather, the FETCH statement retrieves the rows.""When its cursor or cursor variable is opened, %ROWCOUNT is zeroed. Before the first fetch, %ROWCOUNT yields 0. Thereafter, it yields the number of rows fetched so far. The number is incremented if the last fetch returned a row"One option would be run the SQL part of cursor as separate query and get a row count before you open and access the cursor.惨!
1 declare
2 n number;
3 cursor c1 is select 1 from a016;
4 begin
5 open c1;
6 loop
7 fetch c1 into n;
8 exit when c1%notfound;
9 end loop;
10 n:=c1%rowcount;
11 dbms_output.put_line(n);
12 close c1;
13 dbms_output.put_line(n);
14* end;
"Rows in the result set are not retrieved when the OPEN statement is
executed. Rather, the FETCH statement retrieves the rows.""When its cursor or cursor variable is opened, %ROWCOUNT is zeroed. Before
the first fetch, %ROWCOUNT yields 0. Thereafter, it yields the number of
rows fetched so far. The number is incremented if the last fetch returned a
row"One option would be run the SQL part of cursor as separate query and get a
row count before you open and access the cursor.惨!
%R0WCOUNT:其值为在该光标上到目前为止执行FETCH语句所返回的行数。
光标打开时%ROWCOUNT初始化为零,每执行一次FETCH如返回一行刚%ROWCOUNT增1。
OPEN crTp FOR SELECT col1,(select count(*) from t1) FROM t1;
LOOP
FETCH crTp INTO cColumnName,rowcount;
EXIT WHEN crTp%NOTFOUND;
END LOOP;
其中rowcount就是游标的记录总数了。