首页 > 学院 > 开发设计 > 正文

pl/SQL编程(五)参照变量

2019-11-08 20:43:58
字体:
来源:转载
供稿:网友

参照变量 用于存放数值指针的变量,通过使用参照变量可以使应用程序共享相同对象,从而降低占用的空间可以使用游标变量(ref cursor)和对象类型变量(ref obj_type)两种参照变量 使用游标时,当定义游标不需要指定相应的select语句,但是当使用游标时(open时)需要指定select语句 实例如下:

1.编写pl/sql块 可以输入部门号,并显示部门所有的员工姓名和工资

declare--定义游标类型sp_emp_cursortype sp_emp_cursor is ref cursor;--定义游标变量emp_cursor sp_emp_cursor;--定义变量v_name emp.name%type;v_sal emp.sal%type;begin--执行部分--把emp_cursor和一个select语句结合open emp_cursor for select name,sal from emp where deptno=&no;--循环取数据loopfetch emp_cursor into v_name,v_sal;--判断emp_cursor 为空则退出exit when emp_cursor%notfound;dbms_output.put_line('姓名是:'||v_name||'工资是:'||v_sal);end loop;--关闭游标close emp_cursor;end;/
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表