事例1:

create or replace procedure sp_addProjectQj(
ret out number,
flowid in number --流程Id
)
as
cursor c_design is
select * from LC_VR_Detail where lc_crm_visitreport_Id = flowid and dd_status != 2;
c_row c_design%rowtype;
v_id number;
begin
for c_row in c_design loop
pnextid('T_XMSJQJ',v_id);
--项目涉及器件(id,项目名称,器件) values --design明细表(v_id,项目名称,器件名称)
insert into T_XMSJQJ(id,f2,sj,fqj,f3,cj,fsl,fbz,fqzje,fldknx,fldjz,fcyyy,fdocnum,fgdyy,f6,bz)
values (v_id,c_row.dd_project,c_row.DD_Newtime,c_row.dd_name,c_row.dd_model,c_row.dd_brand,
c_row.dd_num,c_row.dd_currency,c_row.dd_HideCash,c_row.DD_SureChance,c_row.DD_SureEvolve,
c_row.DD_Difference,c_row.dd_docnum,c_row.dd_whyclose,c_row.dd_Designinstatus,c_row.dd_remarks );
commit;
end loop;
ret:=1;
EXCEPTION
WHEN OTHERS THEN
ret:=-1;
end;

事例2:

CREATE OR REPLACE PROCEDURE sp_empAttendSetAdd (
    o_Ret out int,
  o_RetInfo out varchar2,
  i_type in int, --类别:1|部门;2|员工;3|角色
  i_company int,--公司
  i_deptEmpRole in varchar2, --部门或员工或角色
  i_validDate date,--生效日期
  i_invalidDate date,--失效日期
  i_user int, --登录用户
  i_attendTeam int --考勤班组
)
is

v_nextid number;

v_worktype number;
v_invalidDate date;
v_sql varchar2(5000);
v_strSql varchar2(5000);
cur_data types.cursorType;
v_employeeId number;
v_deptId number;
v_flag1 number;
v_flag2 number;

begin
  v_invalidDate:=i_invalidDate;
  --失效日期为空时,取当前年份的年底时间
  if i_invalidDate is null then
    --select add_months(trunc(i_validDate, 'yyyy'), 12)-1 into v_invalidDate from dual;
    select max(a.fenddate) into v_invalidDate from HRM_AttendPeriod a where a.fcompany = i_company;
  end if;

  --判断生效时间至失效时间是否有未开账的考核期间
  select count(1) into v_flag1 from Hrm_Attendperiod a where a.fbegindate<=i_validDate and i_validDate<=a.fenddate and a.fcompany = i_company;
  select count(1) into v_flag2 from Hrm_Attendperiod a where a.fbegindate<=nvl(i_invalidDate,v_invalidDate) and nvl(i_invalidDate,v_invalidDate)<=a.fenddate and a.fcompany = i_company;
  if v_flag1=0 or v_flag2=0 then
    o_Ret:=-1;
    o_RetInfo:='该生效时间段存在考勤期间未开账!';
    return;
  end if;

  --查找工作种类
  select fworktype into v_worktype from HRM_AttendTeam where id = i_attendTeam;

  --类别是部门
  if i_type=1 then
    v_sql:=' instr('';''||'''||i_deptEmpRole||'''||'';'','';''||a.fdept||'';'')>0';
  --类别是员工
  elsif i_type=2 then
    v_sql:=' instr('';''||'''||i_deptEmpRole||'''||'';'','';''||a.id||'';'')>0';
  --类别是角色
  elsif i_type=3 then
    v_sql:=' a.id in ( select femployee from tuser where id in (select distinct userid from lbmember where

instr('';''||'''||i_deptEmpRole||'''||'';'','';''||roleid||'';'')>0

and orgid in (select id from lbOrganization where fun_findComOrgId(ID)='''||i_company||''')))';
  end if;

  v_strSql:= 'select a.id,a.fdept from PUB_Employee a where '||v_sql;
  --dbms_output.put_line(v_strSql);
  open cur_data for v_strSql;
  loop
    fetch cur_data into v_employeeId,v_deptId;
    exit when cur_data%notfound;

    --生效时间段交叉检查
    sp_HRM_EmpAttendSet(o_Ret,o_RetInfo,i_company,v_employeeId,i_validDate,i_invalidDate);
    if o_Ret<0 then
      return;
    end if;

    pnextid('HRM_EmpAttendSet',v_nextid);
    --新增员工考勤设置
    insert into HRM_EmpAttendSet(id,Fcompany,Fdept,Femployee,Fattendteam,Fcard,Fvaliddate,Finvaliddate,Fuser,Ftime)
    values(v_nextid,i_company,v_deptId,v_employeeId,i_attendTeam,1,i_validDate,i_invalidDate,i_user,sysdate);
    commit;

    for cs_attendPeriod in (
      --查询考勤期间
      select a.id from HRM_AttendPeriod a where a.fbegindate between i_validDate and nvl(i_invalidDate,v_invalidDate)
    )
    loop
      sp_HRM_WorkDuty(o_Ret,o_RetInfo,1,'批量新增员工考勤设置自动完成排班',i_user,cs_attendPeriod.id,v_worktype,v_employeeId);
      --add By kaixian.zheng
      sp_HRM_WorkDuty_Temp(o_Ret,o_RetInfo,1,'批量新增员工考勤设置自动完成排班',i_user,cs_attendPeriod.id,v_worktype,v_employeeId);
      if o_Ret<0 then
        return;
      end if;
      commit;
    end loop;
  commit;
end loop;
close cur_data;
end sp_empAttendSetAdd;

21. oracle游标循环例子的更多相关文章

  1. oracle游标循环的嵌套

    完成批量修改user_tables中的所有表的栏位名(从MS SQL导入过来,发现大小写问题,造成很多麻烦) 存储过程见下: -- Created on 2012/3/14 by FREE decla ...

  2. Oracle游标-循环查询表中数据(表名),并执行

    Oralce 表中存有一个字段,该字段存储表名,要把该表中的所有表名查询出来(即表名结果集),且执行结果集from 表名结果集: declare v_ccount ); --定义一个游标变量 curs ...

  3. Oracle游标循环更新数据案例

    declare v_XTXMBH number; v_ZJZJZJRQ varchar2(40); cursor c_job is SELECT XT.XTXMBH AS XTXMBH, QJ.ZJZ ...

  4. oracle for loop循环以及游标循环

    1. for in loop形式 DECLARE    CURSOR c_sal IS SELECT employee_id, first_name || last_name ename, salar ...

  5. oracle 游标使用大全

    转:http://www.cnblogs.com/fjfzhkb/archive/2007/09/12/891031.html oracle的游标和例子! 游标-----内存中的一块区域,存放的是se ...

  6. oracle存储过程的例子

    oracle存储过程的例子 分类: 数据(仓)库及处理 2010-05-03 17:15 1055人阅读 评论(2)收藏 举报 认识存储过程和函数 存储过程和函数也是一种PL/SQL块,是存入数据库的 ...

  7. Oracle游标介绍

    Oracle游标使用详解: 游标: 用来查询数据库,获取记录集合(结果集)的指针,我们所说的游标通常是指显式游标,因此从现在起没有特别指明的情况,我们所说的游标都是指显式游标.要在程序中使用游标,必须 ...

  8. [转载]oracle游标概念讲解

    原文URL:http://www.2cto.com/database/201203/122387.html ORACLE游标概念讲解 什么是游标?  ①从表中检索出结果集,从中每次指向一条记录进行交互 ...

  9. Oracle 游标使用总结(好文章)

    游标(CURSOR)也叫光标,在关系数据库中经常使用,在PL/SQL程序中可以用CURSOR与SELECT一起对表或者视图中的数据进行查询并逐行读取. Oracle游标分为显示游标和隐式游标. 显示游 ...

随机推荐

  1. dfs遍历痕迹的清理

    dfs 根据遍历效果分为 有痕迹遍历和无痕迹遍历, 有痕迹遍历就是对遍历过程对全局变量进行了修改的遍历(如POJ3009中的冰球问题,每次遍历会对地图造成影响),无痕迹遍历就是不对全局变量修改的遍历( ...

  2. WC游记

    第一次来WC,感觉这种集训真吼啊 day0 火车上快速补习了莫队,和AC自动姬,AC自动姬以前就会写只不过太久没写忘了我会了= = 莫队只是学习了做法,还没有做过题…… 本来想再复习一下后缀数组,然后 ...

  3. oclif cli app开发简单试用

    oclif 是heroku 开源的cli 开发框架,有一篇关于12 factor cli app 开发的文章很值得看看 https://medium.com/@jdxcode/12-factor-cl ...

  4. Microsoft OWIN

    About OWIN defines a standard interface between .NET web servers and web applications. The goal of t ...

  5. juc并发工具类之CountDownLatch闭锁

    import java.util.concurrent.CountDownLatch; /** * 闭锁: 在进行某些运算时, 只有其他所有线程的运算全部完成,当前运算才继续执行(程序流中加了一道栅栏 ...

  6. pysonar

    为了看懂王垠Pysonar,我应该掌握哪些知识? 我希望自己做出一个Python的静态类型检查工具,就像Pysonar所做的那样,只是我还想扩展更多的功能.我应该如何学习?   Erlang里的Dia ...

  7. python版 google密码认证器

    #!/usr/bin/env python # -*- coding:utf-8 -*- import hmac, base64, struct, hashlib, time def calGoogl ...

  8. ML(3): 贝叶斯方法

    对于分类问题,我们每个人每天都在执行分类操作,只是我们没有意识到罢了.例如,当你看到一个陌生人,你的脑子下意识判断TA是男是女:你可能经常会走在路上对身旁的朋友说“这个人一看就很有钱.那边有个非主流” ...

  9. 企业微信jssdk分享接口管理系统

    服务项目 新手技术咨询 企业技术咨询 定制开发 服务说明 QQ有问必答 QQ.微信.电话 微信开发.php开发,网站开发,系统定制,小程序开发 价格说明 200元/月 1000/月 商议       ...

  10. view的setTag() 和 getTag()应用 ViewHolder

    转自 http://www.cnblogs.com/qingblog/archive/2012/07/03/2575140.html View中的setTag(Onbect)表示给View添加一个格外 ...