PLSQL带参数的CURSOR

简介:

开始

复制代码
SET SERVEROUTPUT ON;

DECLARE
  v_empno emp.empno%TYPE;
  v_ename emp.ename%TYPE;
  
  CURSOR emp_cursor
  (p_deptno NUMBER,p_job VARCHAR2) IS
  SELECT empno,ename FROM emp WHERE deptno=p_deptno AND JOB=p_job;
  
  emp_record emp_cursor%ROWTYPE;
  
BEGIN

LOOP

  IF NOT emp_cursor%ISOPEN  THEN
     OPEN emp_cursor(30,'SALESMAN');
  END IF; 
  
  FETCH emp_cursor INTO  emp_record; 
  EXIT WHEN emp_cursor%NOTFOUND;
  
  dbms_output.put_line
     ('rowcount is:'|| emp_cursor%ROWCOUNT || '-- empno is:' || emp_record.empno 
        || '-- emp name is:' || emp_record.ename);

END LOOP;

IF emp_cursor%ISOPEN  THEN
     dbms_output.put_line('Now to close cursor!');
     CLOSE emp_cursor;
END IF; 
  
dbms_output.put_line('-------------------------------');

LOOP

  IF NOT emp_cursor%ISOPEN  THEN
     OPEN emp_cursor(20,'CLERK');
  END IF; 
  
  FETCH emp_cursor INTO  emp_record; 
  EXIT WHEN emp_cursor%NOTFOUND;
  
  dbms_output.put_line
     ('rowcount is:'|| emp_cursor%ROWCOUNT || '-- empno is:' || emp_record.empno 
        || '-- emp name is:' || emp_record.ename);

END LOOP;

IF emp_cursor%ISOPEN  THEN
     dbms_output.put_line('Now to close cursor!');
     CLOSE emp_cursor;
END IF; 


END;
/
复制代码

运行结果

复制代码
anonymous block completed
rowcount is:1-- empno is:7499-- emp name is:ALLEN
rowcount is:2-- empno is:7521-- emp name is:WARD
rowcount is:3-- empno is:7654-- emp name is:MARTIN
rowcount is:4-- empno is:7844-- emp name is:TURNER
Now to close cursor!
-------------------------------
rowcount is:1-- empno is:7369-- emp name is:SMITH
rowcount is:2-- empno is:7876-- emp name is:ADAMS
Now to close cursor!
复制代码

 

结束








本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/11/14/2770170.html,如需转载请自行联系原作者

目录
相关文章
|
Oracle 关系型数据库 Linux
[20171231]PLSQL使用绑定变量.txt
[20171231]PLSQL使用绑定变量.txt --//一些应用程序开发使用的绑定变量是:1,:2之列的语句,要调优这些语句必须写成如下: 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING              ...
1205 0