create or replace procedure Getyc is
  v_id VARCHAR2(36);
  v_date VARCHAR2(4);

begin
  declare
    begin
      for i in (select
           c.xqbm
      from T_BAS_GCJBXX c
     where c.id in (select a.id
                      from T_BAS_GCJBXX a
                     where a.scszbg = 1
                    minus
                    select b.gcid
                      from T_BAS_SZRBJCXX b
                     where TO_CHAR(b.bgrq, 'YYYY/MM/DD') =
                           TO_CHAR(SYSDATE, 'YYYY/MM/DD')) group by c.xqbm) LOOP
                           v_id := SYS_GUID();
                           insert into T_BGYCSBJL (ID, SSXQ, BGRQ, DQZT, SBSJ, DXFSZT, BGLX) VALUES(v_id,i.xqbm,SYSDATE,0,SYSDATE,0,0);
                           insert into T_RBYCSBMX(ID, SBJLID, DQZT, SBRQ, GCID) select SYS_GUID() ID,
                                                                                         v_id SBJLID,
                                                                                            0 DQZT,
                                                                                      SYSDATE SBRQ,
                                                                                         c.id GCID
                                                                                           from T_BAS_GCJBXX c where c.id in (select a.id
                                                                                                                               from T_BAS_GCJBXX a
                                                                                                                               where a.scszbg = 1
                                                                                                                               minus
                                                                                                                               select b.gcid
                                                                                                                                from T_BAS_SZRBJCXX b
                                                                                                                                where TO_CHAR(b.bgrq, 'YYYY/MM/DD') =
                                                                                                                                TO_CHAR(SYSDATE, 'YYYY/MM/DD')
                                                                                                                                ) and c.xqbm=i.xqbm;
             END LOOP;
              end;
              declare
              begin
               v_date := TO_CHAR(SYSDATE,'DD');
              if(v_date='25') then
           insert into T_BGYCSBJL(ID,SSXQ,BGRQ,DQZT,SBSJ,DXFSZT,BGLX)
          select SYS_GUID() ID,
                 c.xqbm SSXQ,
                 SYSDATE BGRQ,
                 0 DQZT,
                 SYSDATE SBSJ,
                 0 DXFSZT,
                 1 BGLX
                 from T_BAS_GCJBXX c
                 where c.xqbm in (select a.xqbm
                                       from T_BAS_GCJBXX a
                                       where a.scszbg=1
                                       minus
                                   select b.sbdw
                                   from T_SZYBMBXX b
                                   where TO_CHAR(b.bgny,'YYYY/MM')=
                                   TO_CHAR(SYSDATE,'YYYY/MM')) group by c.xqbm;

end if;
               end;
             commit;

end Getyc;

begin
sys.dbms_scheduler.set_attribute(name => 'WFNCYS.JOB_YC', attribute => 'repeat_interval', value => 'Freq=DAILY;ByHour=17;ByMinute=30;BySecond=00');
end;

使用游标的存储过程:

create or replace procedure Getyc is
v_id VARCHAR2(36);
v_date VARCHAR2(4);
y_date VARCHAR2(4);
needd number;

/*定义查询结果集游标,注意游标存储的是结果集的快照*/
cursor gcjbxx_cur is
select c.xqbm from T_BAS_GCJBXX c

where c.id in(
select a.id from T_BAS_GCJBXX a
where a.scszbg = 1
minus
select b.gcid from T_BAS_SZRBJCXX b
where TO_CHAR(b.bgrq, 'YYYY/MM/DD')=TO_CHAR(SYSDATE, 'YYYY/MM/DD')) group by c.xqbm;
/*定义与游标类型匹配的行记录对象*/
gcjbxx_rec gcjbxx_cur%rowtype;

cursor jqtemp_cur is
select sjsj from t_bas_jqtemp;
jqtemp_rec jqtemp_cur%rowtype;

begin
select needduty into needd from workattendence
where TO_CHAR(datetime, 'YYYY/MM/DD')=TO_CHAR(SYSDATE, 'YYYY/MM/DD');
if(needd=1) then
/*打开游标*/
open gcjbxx_cur;
LOOP
fetch gcjbxx_cur into gcjbxx_rec;
/*当未找到记录时退出循环*/
exit when gcjbxx_cur%notfound;
v_id := SYS_GUID();
insert into T_BGYCSBJL (ID, SSXQ, BGRQ, DQZT, SBSJ, DXFSZT, BGLX)
VALUES(v_id,gcjbxx_rec.xqbm,SYSDATE,0,SYSDATE,0,0);
insert into T_RBYCSBMX(ID, SBJLID, DQZT, SBRQ, GCID)
select SYS_GUID() ID,v_id SBJLID,0 DQZT,SYSDATE SBRQ,c.id GCID from T_BAS_GCJBXX c
where c.id in (select a.id from T_BAS_GCJBXX a where a.scszbg = 1
minus
select b.gcid from T_BAS_SZRBJCXX b
where TO_CHAR(b.bgrq, 'YYYY/MM/DD') = TO_CHAR(SYSDATE, 'YYYY/MM/DD')) and c.xqbm=gcjbxx_rec.xqbm;
/*关闭游标*/
END LOOP;
close gcjbxx_cur;

v_date := TO_CHAR(SYSDATE,'DD');

if(v_date='25') then
insert into T_BGYCSBJL(ID,SSXQ,BGRQ,DQZT,SBSJ,DXFSZT,BGLX)
select SYS_GUID() ID,
c.xqbm SSXQ,
SYSDATE BGRQ,
0 DQZT,
SYSDATE SBSJ,
0 DXFSZT,
1 BGLX
from T_BAS_GCJBXX c
where c.xqbm in (
select a.xqbm from T_BAS_GCJBXX a where a.scszbg=1
minus
select b.sbdw from T_SZYBMBXX b
where TO_CHAR(b.bgny,'YYYY/MM')=TO_CHAR(SYSDATE,'YYYY/MM')) group by c.xqbm;
end if;

/*开始遍历t_bas_jqtemp*/
open jqtemp_cur;
loop
fetch jqtemp_cur into jqtemp_rec;

exit when jqtemp_cur%notfound;
for i in (
select c.xqbm from T_BAS_GCJBXX c
where c.id in (
select a.id from T_BAS_GCJBXX a where a.scszbg = 1
minus
select b.gcid from T_BAS_SZRBJCXX b
where TO_CHAR(b.bgrq, 'YYYY/MM/DD')=TO_CHAR(jqtemp_rec.sjsj, 'YYYY/MM/DD')) group by c.xqbm)
LOOP
v_id := SYS_GUID();
insert into T_BGYCSBJL (ID, SSXQ, BGRQ, DQZT, SBSJ, DXFSZT, BGLX)
VALUES(v_id,i.xqbm,jqtemp_rec.sjsj,0,jqtemp_rec.sjsj,0,0);
insert into T_RBYCSBMX(ID, SBJLID, DQZT, SBRQ, GCID)
select SYS_GUID() ID,v_id SBJLID,0 DQZT,jqtemp_rec.sjsj SBRQ,c.id GCID from T_BAS_GCJBXX c
where c.id in (select a.id from T_BAS_GCJBXX a where a.scszbg = 1
minus
select b.gcid from T_BAS_SZRBJCXX b
where TO_CHAR(b.bgrq, 'YYYY/MM/DD') = TO_CHAR(jqtemp_rec.sjsj, 'YYYY/MM/DD')) and c.xqbm=i.xqbm;
END LOOP;

y_date := TO_CHAR(jqtemp_rec.sjsj,'DD');
if(y_date='25') then
insert into T_BGYCSBJL(ID,SSXQ,BGRQ,DQZT,SBSJ,DXFSZT,BGLX)
select SYS_GUID() ID,
c.xqbm SSXQ,
jqtemp_rec.sjsj BGRQ,
0 DQZT,
jqtemp_rec.sjsj SBSJ,
0 DXFSZT,
1 BGLX
from T_BAS_GCJBXX c
where c.xqbm in (
select a.xqbm from T_BAS_GCJBXX a where a.scszbg=1
minus
select b.sbdw from T_SZYBMBXX b
where TO_CHAR(b.bgny,'YYYY/MM')=TO_CHAR(jqtemp_rec.sjsj,'YYYY/MM')) group by c.xqbm;
end if;
end loop;
close jqtemp_cur;

DELETE FROM t_bas_jqtemp;

else
insert into t_bas_jqtemp (sjsj,id) VALUES(SYSDATE,sys_guid());
end if;
commit;
end Getyc;

oracle 存储过程的写法的更多相关文章

  1. Oracle存储过程中跳出循环的写法

    注:本文来源于: <  Oracle存储过程中跳出循环的写法   > Oracle存储过程中跳出循环的写法 记录exit和return的用法 1:exit用来跳出循环 loop IF V_ ...

  2. Oracle存储过程(增、删、改)写法、oracle执行存储过程

    Oracle存储过程(增.删.改)写法 发布时间: 2010-3-24 11:07    作者: ZHF    来源: 51Testing软件测试网采编 字体:  小  中  大  | 上一篇 下一篇 ...

  3. Oracle的存储过程基本写法

    转: Oracle的存储过程基本写法 目录 1.1,Oracle存储过程简介: 1.2,创建存储过程的语法: 2.0,游标的使用.看到的一段解释很好的概念,如下: 回到顶部 1.1,Oracle存储过 ...

  4. oracle 存储过程 动态sql语句

    一.在oracle项目开发中越到问题: 在利用ODP向oracle中插入数据时,如果这样写:   insert into clobTable (id, story) values(1,'....'); ...

  5. Oracle 存储过程_(收集)

    oracle 存储过程的基本语法 1.基本结构 CREATE OR REPLACE PROCEDURE 存储过程名字(    参数1 IN NUMBER,    参数2 IN NUMBER) IS变量 ...

  6. oracle 存储过程使用动态sql

    Oracle存储过程使用动态SQL 有两种写法:用 DBMS_SQL 或 execute immediate,建议使用后者. DDL和DML (注意DDL中可以用拼接字符串的方法用来create ta ...

  7. Oracle存储过程——日常记录

    代码规范 Oracle存储过程,关键字大写,变量小写并以v_开头,规范代码,提高可读性 赋值与判断符号 Oracle存储过程,变量赋值使用 := 符号,条件判断直接用 = 符号. 变量声明需在 beg ...

  8. 数据库周刊30丨数据安全法草案将亮相;2020数据库产业报告;云南电网上线达梦;达梦7误删Redo Log;Oracle存储过程性能瓶颈;易鲸捷实践案例……

    摘要:墨天轮数据库周刊第30期发布啦,每周1次推送本周数据库相关热门资讯.精选文章.干货文档. 热门资讯 1.数据安全法草案即将亮相:将确立数据分级分类管理.应急处置制度[摘要]数据安全法草案即将在本 ...

  9. oracle 存储过程

    来自:http://www.jb51.net/article/31805.htm Oracle存储过程基本语法 存储过程 1 CREATE OR REPLACE PROCEDURE 存储过程名 2 I ...

随机推荐

  1. aws在线技术峰会笔记-主会场

    容器服务:Elastic container service IoT可以采用无服务器架构.

  2. 做个这样的APP要多久?[转]

    这是一个“如有雷同,纯属巧合”的故事,外加一些废话,大家请勿对号入座.开始了…… 我有些尴尬地拿着水杯,正对面坐着来访的王总,他是在别处打拼的人,这几年据说收获颇丰,见移动互联网如火如荼,自然也想着要 ...

  3. B:冷血格斗场

    总时间限制: 1000ms 内存限制: 65536kB描述为了迎接08年的奥运会,让大家更加了解各种格斗运动,facer新开了一家冷血格斗场.格斗场实行会员制,但是新来的会员不需要交入会费,而只要同一 ...

  4. ListView.DragEnter触发不了

    经过千百度的搜索之后,终于找到了一点线索,原文是:https://msdn.microsoft.com/en-us/magazine/mt185571.aspx 有能力的可以参阅原文,想省事的可以等待 ...

  5. Android开发--FrameLayout的应用

    1.简介 frameLayout为框架布局,该布局的特点为层层覆盖,即最先放置的部件位于最下层,最后放置的部件位于最上层. 2.构建 如图所示,该视图中有五个TextView.其中,tv1放置在最底层 ...

  6. SSM框架学习之高并发秒杀业务--笔记4-- web层

    在前面几节中已经完成了service层和dao层,到目前为止只是后端的设计与编写,这节就要设计到前端的设计了.下面开始总结下这个秒杀业务前端有哪些要点: 1. 前端页面的流程 首先是列表页,点某个商品 ...

  7. 媒体查询判断ipad与iPhone各版本i

    /* 判断ipad */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px){ /* s ...

  8. JDE Develop Server分别安装DV PY PD后WEBSERVER问题

    一般安装时一次性安装完DV\PY\PD环境后,再安装WEBSERVER时只需要修改一次配置文件即可,但如果先安装顺序如下: DV->WEBSERVER->PY 此时,配置程序被初始化,必须 ...

  9. SEO命令之”site“运用详解

    一.“site”基本介绍: 都知道要想查询一个特定网站的收录状况一般会分为两种情况:一.结果中有返回数据,则表明该网站已被收录:二.如果返回数据为空,则该网站未被收录.如果是以前已被收录的,现在来查没 ...

  10. Octopus系列之各个页面调用示例2

    判断登陆的调用 #if(${islogin}) <span> ${Oct_Welcome} or <a href="${siteurl}customer/logout/&q ...