对PLSQL的cursor 的rowcount 的理解

开始

rowcount 并不是定义或open了cursor,就是固定的值,它随着每次fetch而累计:

--INDEX BY Table
SET SERVEROUTPUT ON;

DECLARE
  v_empno emp.empno%TYPE;
  v_ename emp.ename%TYPE;
  
  CURSOR emp_cursor IS
  SELECT empno,ename from emp where empno<>1000;
  
BEGIN

LOOP

  IF NOT emp_cursor%ISOPEN  THEN
     OPEN emp_cursor;
  END IF; 
  
  FETCH emp_cursor INTO  v_empno,v_ename; 
  EXIT WHEN emp_cursor%NOTFOUND;
   
  dbms_output.put_line(
'rowcount is:'|| emp_cursor%ROWCOUNT || '-- empno is:' || v_empno || '-- emp name is:' || v_ename); END LOOP; END; /

运行结果:

anonymous block completed
rowcount is:1-- empno is:7369-- emp name is:SMITH
rowcount is:2-- empno is:7499-- emp name is:ALLEN
rowcount is:3-- empno is:7521-- emp name is:WARD
rowcount is:4-- empno is:7566-- emp name is:JONES
rowcount is:5-- empno is:7654-- emp name is:MARTIN
rowcount is:6-- empno is:7698-- emp name is:BLAKE
rowcount is:7-- empno is:7782-- emp name is:CLARK
rowcount is:8-- empno is:7788-- emp name is:SCOTT
rowcount is:9-- empno is:7839-- emp name is:KING
rowcount is:10-- empno is:7844-- emp name is:TURNER
rowcount is:11-- empno is:7876-- emp name is:ADAMS
rowcount is:12-- empno is:7900-- emp name is:JAMES
rowcount is:13-- empno is:7902-- emp name is:FORD
rowcount is:14-- empno is:7934-- emp name is:MILLER

结束

posted @ 2012-11-14 10:02  健哥的数据花园  阅读(5662)  评论(0编辑  收藏  举报