out参数以及使用光标问题

来源:互联网 发布:分页查询sql语句 编辑:程序博客网 时间:2024/05/19 21:42

/*
查询某个员工的姓名 月薪 职位

*/
create or replace procedure queryEmpInfo(eno in number,
pename out varchar2,
psal out number,
pjob out varchar2)
as
begin
select ename,sal,empjob into pename,psal,pjob from emp where empno=eno;

end;
/

–光标: 使用游标查询员工姓名和工资,并打印

/*
光标的属性:
**%isopen 是否被打开
%rowcount 行数
%notfound 是否有值**
*/

set serveroutput on

declare
–光标
cursor cemp is select ename,sal from emp;
pename emp.ename%type;
psal emp.sal%type;
begin
open cemp;
loop
–从集合中取值
fetch cemp into pename,psal;
**
exit when cemp%notfound;

dbms_output.put_line(pename||'的薪水是'||psal);

end loop;
close cemp;
end;
/

查询某个部门中所有员工的所有信息

CREATE OR REPLACE
PACKAGE MYPACKAGE AS

type empcursor is ref cursor;
procedure queryEmpList(dno in number,empList out empcursor);

END MYPACKAGE;

CREATE OR REPLACE
PACKAGE BODY MYPACKAGE AS

procedure queryEmpList(dno in number,empList out empcursor) AS
BEGIN

  open empList for select * from emp where deptno=dno;

END queryEmpList;

END MYPACKAGE;

0 0
原创粉丝点击