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. Arduino学习笔记二:修改LED点灯程序

    看了开源社区的LED控制程序,开始上手代码编写,修改,下载以及调试,原文地址:http://www.arduino.cn/thread-1072-1-1.html,这个帖子写的比较通俗易懂. 自己移植 ...

  2. 如何很好的使用Linq的Distinct方法

    Person1: Id=1, Name="Test1" Person2: Id=1, Name="Test1" Person3: Id=2, Name=&quo ...

  3. jquery引用方法时传递参数

    经常到网上去下载大牛们写的js插件.每次只需将js引用并设置下变量就行了,但一直没搞明白原理(主要是大牛们的代码太简练了-,-). 这次弄清了如何传递.设置多个(很多个)参数. 如 方法为functi ...

  4. 轻松解决Linux安装Eclipse方法

    随着Linux的发展,很多人开始学习Linux系统,你了解Linux系统么?你是Linux系统的应用者么?本文为你详细介绍Linux安装Eclipse,为你在学习Linux安装Eclipse时起一定的 ...

  5. Codeforces Round #263 (Div. 1)

    B 树形dp 组合的思想. Z队长的思路. dp[i][1]表示以i为跟结点的子树向上贡献1个的方案,dp[i][0]表示以i为跟结点的子树向上贡献0个的方案. 如果当前为叶子节点,dp[i][0] ...

  6. Android OkHttp完全解析 是时候来了解OkHttp了

    Android OkHttp完全解析 是时候来了解OkHttp了 标签: AndroidOkHttp 2015-08-24 15:36 316254人阅读 评论(306) 收藏 举报  分类: [an ...

  7. Centos 7环境下编译mysql 5.7

    首先在编译之前,我们要了解相关mysql 5.7的编译选项,官网编译选项地址:http://dev.mysql.com/doc/refman/5.7/en/source-configuration-o ...

  8. iOS开发 沙盒路径和使用

    1.模拟器沙盒目录文件都在个人用户名文件夹下的一个隐藏文件夹里,中文叫资源库,他的目录其实是Library.因为应用是在沙箱(sandbox)中的,在文件读写权限上受到限制,只能在几个目录下读写文件: ...

  9. C++ Primer 第九章 顺序容器

    由于书籍上写的已经很经典了,故大部分用图片的形式来阐述概念,代码纯手打进行验证. 1.顺序容器类型:vector.deque.list.forword_list.array.string. 2.顺序容 ...

  10. javascript的一些基础

    当复制的两个变量的地址不同时他们是不相等的如下代码所示 function getFunction(value){ return function(value){ return value; } } v ...