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)