读书人

弱门类游标

发布时间: 2013-03-21 10:08:17 作者: rapoo

弱类型游标

SQL> editWrote file afiedt.buf  1   declare  2   type curemptype is ref cursor;  3   curemp_ref curemptype;  4   command char(1);  5   currow emp%rowtype;  6   theename emp.ename%type;  7  begin  8  dbms_output.put_line('请输入操作命令:1-查找deptno=30的员工姓名;2查找job=manager的员工信息');  9   command :=&命令; 10  if command='1' 11  then dbms_output.put_line('输入命令:1'); 12  open curemp_ref for select ename from emp where deptno=30; 13  loop 14  fetch curemp_ref into theename; 15  exit when curemp_ref%notfound; 16  dbms_output.put_line(theename); 17  end loop; 18  close curemp_ref; 19  else 20  dbms_output.put_line('输入命令:2'); 21  open curemp_ref for select * from emp where job='MANAGER'; 22  loop 23  fetch curemp_ref into currow; 24  exit when curemp_ref%notfound; 25  dbms_output.put_line('编号:'||currow.empno||'姓名:'||currow.ename||'职位:'||currow.job); 26  end loop; 27  close curemp_ref; 28  end if; 29* end;SQL> /Enter value for 命令: 2old   9:  command :=&命令;new   9:  command :=2;请输入操作命令:1-查找deptno=30的员工姓名;2查找job=manager的员工信息           输入命令:2                                                                     编号:7566姓名:JONES职位:MANAGER                                              编号:7698姓名:BLAKE职位:MANAGER                                              编号:7782姓名:CLARK职位:MANAGER                                              PL/SQL procedure successfully completed.

?

读书人网 >编程

热点推荐