欢迎来到代码驿站!

Oracle

当前位置:首页 > 数据库 > Oracle

详解Oracle游标的简易用法

时间:2021-05-05 15:35:52|栏目:Oracle|点击:

下面看下Oracle游标的简易用法,具体代码如下所示:

create or replace procedure NW_DelYW(iOPERATION_ID number,
                 sUserID   varchar2) is
 sCurDJBH yw_operation_link.djbh%type;
 cursor table_yw(ywid yw_operation.id%type) is
  select * from yw_operation_link t1 where t1.operation_id = ywid;
begin
 for dr in table_yw(iOPERATION_ID) loop
  sCurDJBH := dr.djbh;
  --取得opercationid
  /*  select t1.operation_id
   into sOperationID
   from yw_operation_link t1
  where t1.djbh = sCurDJBH;*/

  --写日志
  insert into log_zfywinfo
   (DJBH,
    DJDL,
    DJXL,
    DLMC,
    XLMC,
    SLR,
    SLRID,
    SQRXM,
    FWZL,
    ZFRQ,
    ZFRID,
    zfr)
   select distinct sCurDJBH,
       t4.id,
       t3.id,
       t4.name,
       t3.name,
       t1.slry,
       t1.slryid,
       t1.SQRXM,
       t1.zl,
       sysdate,
       sUserID,
       (select tt.name from pw_user tt where tt.id=sUserID)
    from yw_operation t1
    join yw_operation_link t2
     on t2.operation_id = t1.ID
    join BUSINESS_TYPE t3
     on t3.id = t1.business_id
    join BUSINESS_CLASS t4
     on t4.id = t3.parent_id
    where t1.ID = dr.operation_id;
exception
 when others then
  rollback;
  dbms_output.put_line(sqlerrm);
end NW_DelYW;

Oracle使用cursor 游标循环添加删除更新。

知识点扩展:

Oracle游标简单示例

使用游标打印员工姓名和薪水

set serveroutput on;
declare
cursor cemp is select ename,sal from emp;
cname emp.ename%type;
csal emp.sal%type;
begin
 open cemp;
 loop
  fetch cemp into cname,csal;
  exit when cemp%notfound;
  dbms_output.put_line(cname || '的薪水是' || csal);
 end loop;
end;
/ 

 带参数的游标

使用游标打印某部门号的所有员工姓名

set serveroutput on;
declare 
cursor cemp(cno emp.deptno%type) is select ename from emp where emp.deptno = cno;
cname emp.ename%type;
begin
 open cemp(10);
 loop 
  fetch cemp into cname;
  exit when cemp%notfound;
  dbms_output.put_line(cname);
  
 end loop;
end;
/ 

总结

上一篇:ORACLE 分区表的设计

栏    目:Oracle

下一篇:ORACLE常见错误代码的分析与解决(一)

本文标题:详解Oracle游标的简易用法

本文地址:http://www.codeinn.net/misctech/115061.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有