zoukankan      html  css  js  c++  java
  • oracle 之 定时任务,存储过程和游标等语法案例

    --定时任务
    declare job20 number;
    begin
    sys.dbms_job.submit(job20,'test1;',sysdate,'sysdate+1');
    end;
    
    --存储过程
    create or replace procedure test3 
    as
    xh_zgid varchar(50);
    xh_zggh varchar(50);
    xh_xm varchar(50);
    xh_grdh varchar(50);
    xh_count int;
    xh_dxxh int;
    xh_zfqnr varchar(100);
    --游标
    CURSOR z1 is
    select zgid,zggh,xm,grdh from RSGL_ZGDA where zxpb=0 and (rdsj is not null )and zxpb=0  AND  to_char(rdsj,'yyyy')!='0001' and   (to_char(rdsj,'MM-dd')) = (to_char(sysdate,'MM-dd'));
    begin
      select  NR into xh_zfqnr  from OA_ZFQ where zfqid='DYSR';
      select to_number(dqz) into xh_dxxh from xt_xhb where bm='SMS_DAIFASONG_DX';
      dbms_output.put_line(xh_dxxh);
       open z1;
        loop 
         fetch z1 into xh_zgid,xh_zggh,xh_xm,xh_grdh;
            if z1 %notfound then exit;end if;
            select count(*) into xh_count from BirthDayTip_jl where zgid=xh_zgid and jlsj=to_char(sysdate,'yyyy/MM/dd');
            dbms_output.put_line(xh_count);
            if xh_count<1 then
              xh_dxxh:=xh_dxxh+1;
              insert into BirthDayTip_jl(zgid,phone,Jlsj) values(xh_zgid,xh_grdh,to_char(sysdate,'yyyy/MM/dd'));
              insert into sms_daifasong_dx(WEIYIBM,FASONGR,FASONGSJ,DUANXINNR,FASONGLX,SHOUJIHM) values(xh_dxxh,xh_xm,sysdate,xh_zfqnr,'3',xh_grdh);
              dbms_output.put_line(xh_dxxh);
              dbms_output.put_line(xh_xm);
              dbms_output.put_line(sysdate);
              dbms_output.put_line(xh_zfqnr);
              dbms_output.put_line(xh_grdh);
              
            end if;
         end loop;
        close z1;
        update xt_xhb set dqz=to_char((xh_dxxh)) where bm='SMS_DAIFASONG_DX';
    end;
    
    --执行存储过程
    
    begin
     test3;
     commit;
    end;

    学到的语法规范:

    --查询语句赋值时

    select  字段名 into 变量名  from 表 where 条件

    --变量名计算时

    变量名:=变量名 运算符 值(变量名+1)

  • 相关阅读:
    转载~基于比较的排序算法的最优下界为什么是O(nlogn)
    关于 cgdb & gdbtui 的输入scanf()问题
    制定ip池内随机生成ip地址
    C 随机不重复元素~转
    随机选取算法 (有权重的记录中选取)~转
    全局变量的教训
    Python字符串的encode与decode研究心得——解决乱码问题
    Python 求最大公因式~辗转相除法
    Python格式化字符串~转
    Python 中的枚举类型~转
  • 原文地址:https://www.cnblogs.com/zmztya/p/8481958.html
Copyright © 2011-2022 走看看