Quantcast
Channel: 容器云计算,Devops,DBA,网络安全。
Viewing all articles
Browse latest Browse all 780

oracle 存储过程与游标返回出多行数据案例

$
0
0


oracle 利用存储过程输入参数返回多行数据方法。


oracle 自带示例scott账号下,利用存储过程返回一行与多行数据方法。

1,利用存储过程返回一行数据,输入参数empno,返回ename与sal.

create or replace procedure p_emp_info(p_empno emp.empno%TYPE)
as
p_ename emp.ename%TYPE;
p_sal   emp.sal%TYPE;
p_count NUMBER;
begin
   select count(e.empno) into p_count from scott.emp e where e.empno=p_empno;
   if p_count=0 then
      return;
    end if;
    select ename,sal into p_ename,p_sal from emp e where e.empno=p_empno;
    DBMS_OUTPUT.put_line('部门号: '||p_empno||'.员工姓名:'||p_ename||'. 工资:'||p_sal);
end;
/

由于select into 每次只能输入一行数据,所以这个方法只能用于一行数据返回。

SQL> set serverout on
SQL> exec p_emp_info(7782);
部门号: 7782.员工姓名:CLARK. 工资:2450
PL/SQL procedure successfully completed


2,使用过程与游标,for in 循环,返回多行数据。

SQL> create or replace procedure get_emp_info(p_deptno emp.deptno%TYPE)

  2  as
  3  cursor empinf is select e.deptno,e.ename,e.sal from emp e;
  4  begin
  5   for i in empinf loop
  6  dbms_output.put_line('部门号:'||i.deptno||'.员工姓名:'||i.ename||'.工资'||i.sal);
  7  end loop;
  8  end;
  9  /
Procedure created

SQL> exec get_emp_info(10);
部门号:10.员工姓名:CLARK.工资2450
部门号:10.员工姓名:KING.工资5000
部门号:10.员工姓名:MILLER.工资1300
PL/SQL procedure successfully completed

SQL>




Viewing all articles
Browse latest Browse all 780

Trending Articles


FORECLOSURE OF REAL ESTATE MORTGAGE


FORTUITOUS EVENT


Pokemon para colorear


Sapos para colorear


Inspirational Quotes For you and Motivates you


Inggit Quotes and Taray Quotes


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.0 by Vimeo.com, Inc.


Vimeo 11.5.1 by Vimeo.com, Inc.


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Girasoles para colorear


OFW quotes : Pinoy Tagalog Quotes


Long Distance Relationship Tagalog Love Quotes


Knock knock jokes


RE: Mutton Pies (frankie241)


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Vimeo 10.7.1 by Vimeo.com, Inc.


Vimeo 11.8.1 by Vimeo.com, Inc.