主业务逻辑函数
create or replace procedure SEND_SMS(i_划帐ID varchar2)
IS
i_workno varchar2(32);
i_ltdno varchar2(16);
i_bid varchar2(16);
i_ysbs varchar2(16);
i_ysje varchar2(16);
i_sdbs varchar2(16);
i_sdje varchar2(16);
i_phone varchar2(12);
i_content varchar2(1000);
i_time varchar2(32);
BEGIN
--1、根据划帐ID查询划帐信息 拼接短信内容
SELECT 生成工号,
a.LTDNO,
信息描述,
应收笔数,
应收金额,
收到笔数,
收到金额,
to_char(生成日期, 'yyyy-mm-dd')
into i_workno, i_ltdno, i_bid, i_ysbs, i_ysje, i_sdbs, i_sdje, i_time
FROM 划帐历史 a, 划帐信息 b
where 划帐ID = i_划帐ID
and a.划帐信息 = b.划帐信息
and 送盘文件 like '%TXNTYP%'
and sendsmsstate is null -- 1表示已发送短信
and 销帐日期 > sysdate - 100 -- 以前没发送的不发送
and 返盘文件 is not null;
i_content := '划帐id:' || i_划帐ID || ',送盘日期:' || i_time || ',总行编号:' || i_bid ||
',应收笔数:' || i_ysbs || '金额:' || i_ysje || ',收到笔数:' || i_sdbs ||
'金额:' || i_sdje;
--2、根据生成工号查询送盘手机号码
begin
select phone into i_phone from tb_sys_user where userno = i_workno;
exception
when no_data_found then
i_phone := 0;
end;
if i_phone <> 0 then
-- 3、插入待发送表 标记划帐历史表已发送短信
insert into wait_deal_mess@wechat
(ID,
TYPE,
HUHAO,
TEL,
MCONTENT,
ADDTIME,
STATE,
PERSON,
DBID,
SMSID,
SMSCOUNT,
CLIENTNAME,
READYTIME,
LTDNO,
SYSTEMID,
SENDINTERFACE)
values
(waitdealmess_sequence.nextval@wechat,
1,
0,
i_phone,
i_content,
sysdate,
1,
i_workno,
0,
51851334,
3,
'划帐通知短信',
null,
'110',
'sms',
'WLSF');
--alter table 划帐历史 add sendsmsstate varchar(4);
update 划帐历史
set sendsmsstate = 1
where 划帐ID = i_划帐ID
and 返盘文件 is not null;
end if;
END;
/
外层入口函数
create or replace procedure SEND_QUEARY_SMS
IS
cursor c_job is
select 划帐ID
from 划帐历史
where 送盘文件 like '%TXNTYP%'
and sendsmsstate is null -- 1表示已发送短信
and 销帐日期 > sysdate - 100 -- 以前没发送的不发送
and 返盘文件 is not null;
c_row c_job%rowtype;
BEGIN
for c_row in c_job loop
send_sms(c_row.划帐ID);
end loop;
END;
/
oracle定时设置
PLSQL在DBMS_Jobs新建定时任务
WHat值输入主业务逻辑函数名称(注意分号结尾);间隔百度自行填写:
每30分钟执行一次:TRUNC(sysdate,'mi') + 30/ (24*60)