在pl / sql块中使用游标打印属于deptno 20的所有员工的姓名,工资和deptno

时间:2017-04-27 16:05:11

标签: oracle plsql

declare
  cursor c_emp is
    select ename,sal,deptno from emp;
  v_name emp.ename%type;
  v_sal emp.sal%type;
  v_deptno emp.deptno%type;
begin
  open c_emp;
  fetch c_emp into v_name,v_sal,v_deptno;
  dbms_output.put_line(v_name||' '||v_sal||' '||v_deptno);
end;
/

2 个答案:

答案 0 :(得分:0)

也许这个......?

declare
  cursor c_emp is
    select ename,sal,deptno from emp;
  v_name emp.ename%type;
  v_sal emp.sal%type;
  v_deptno emp.deptno%type;
begin
    open c_emp;
        loop    
            fetch c_emp into v_name, v_sal, v_deptno;
            exit when c_emp%NOTFOUND;
            dbms_output.put_line(v_name||' '||v_sal||' '||v_deptno);
        end loop;
    close c_emp;
end;
/

答案 1 :(得分:0)

declare
  cursor c_emp is
    select ename,sal,deptno from emp where deptno=20;
  v_name emp.ename%type;
  v_sal emp.sal%type;
  v_deptno emp.deptno%type;
begin
    open c_emp;
        loop    
            fetch c_emp into v_name, v_sal, v_deptno;
            exit when c_emp%NOTFOUND;
            dbms_output.put_line(v_name||' '||v_sal||' '||v_deptno);
        end loop;
    close c_emp;
end;
/