Oracle高级编程
存储过程
PL/SQL procedure successfully completed
SQL> declare
2 --创建一个游标类型
3 type demo_emp_cursor is ref cursor ;
4 --实例化一个demo_emp_cursor类型的对象
5 test_cursor demo_emp_cursor;
6 --定义变量
7 v_ename emp.ename%type;
8 v_sal emp.sal%type;
9 begin
10 --把游标加入SELECT语句中
11 open test_cursor for select ename , sal into v_ename,v_sal from emp;
12 --开始循环
13 Loop
14 --游标指向数据
15 fetch test_cursor into v_ename,v_sal;
16 exit when test_cursor%notfound ;
17 dbms_output.put_line('姓名:'||v_ename||' 工资:'||v_sal);
18 end loop;
19 close test_cursor;
20 end;
21 /
姓名:SMITH 工资:1400