事例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. HashMap Hashtable LinkedHashMap TreeMap

    // Map<String, String> map = new HashMap<String, String>(); // bb aa cc Map<String, S ...

  2. vue components

    https://github.com/vuejs/awesome-vue#components--libraries

  3. 【java规则引擎】《Drools7.0.0.Final规则引擎教程》第4章 4.2 no-loop

    转载至:https://blog.csdn.net/wo541075754/article/details/75201934 no-loop 定义当前的规则是否不允许多次循环执行,默认是 false, ...

  4. jQuery插件制作方法详解

        jQuery插件制作方法详解   jquery插件给我的感觉清一色的清洁,简单.如Jtip,要使用它的功能,只需要在你的元素的class上加 上Jtip,并引入jtip.js及其样式即可以了. ...

  5. Eclipse+Spring学习(一)环境搭建(转)

    最近由于投了一家公司实习,他要java工程师,而我大学3年的精力都花到了ASP.NET和前端上面,到找工作的时候才发现大公司不要.NET的,所以马上转型java...由于网上的高手都不屑于写这类文章, ...

  6. 进程间通信--POSIX信号量

    1.未决和阻塞标志可以用相同的数据类型sigset_t来存储,sigset_t称为信号集,这个类型可以表示每个信号的“有效”或“无效”状态,在阻塞信号集中“有效”和“无效”的含义是该信号是否被阻塞,而 ...

  7. oracle 查某一列有重复值的记录

    -- 查找重复记录select names,num from test where rowid != (select max(rowid)                  from test b   ...

  8. ActiveMQ集群方案

    集群方案主要为了解决系统架构中的两个关键问题:高可用和高性能.ActiveMQ服务的高可用性是指,在ActiveMQ服务性能不变.数据不丢失的前提下,确保当系统灾难出现时ActiveMQ能够持续提供消 ...

  9. RAC2——11g Grid Infrastructure的新机制

    版权声明:本文为博主原创文章,未经博主允许不得转载. 可以看到,最初CRS(Cluster Ready Services)名词的起源就是因为10.1中作为集群软件的原因.后来经历了Clusterwar ...

  10. CC2530低功耗设置(针对终端设备)

    一. 终端设备只完成发送数据 1.开启POWER_SAVING 预编译 2.f8wConfig_cfg 中的RFD_RCVC_ALWAYS_ON=FALSE 3.f8wConfig_cfg中四个DPo ...