sql 存储过程 for in loop 使用 业务


declare
begin
for tttt in
(select temp.c_id
from (select cst.c_tci_id, max(ins.T_END_DATE) as endDate
from tb_test_1 t1, tb_test_2 t2
where t1.c_id = t2.c_id
and t1.C_DEL = '0'
group by c_tci_id) temp
where endDate < sysdate)
loop
update tb_test_1 t1
set t1.c_stat ='0'
where t1.c_id = tttt.c_id;
--commit;
end loop;
end;

--
declare
begin
for thecst in
(select temp.c_tci_id
from (select cst.c_tci_id, max(ins.T_END_DATE) as insDate
from tb_test1 cst, tb_test2 ins
where cst.c_tci_id = ins.c_cst_id
and cst.C_DEL = '0'
--and cst.c_stat = '0'
and cst.C_NO_RELEASE = '1'
and ins.C_DEL = '0'
and ins.c_stat is null
and ins.c_is_telesale_ply is null
group by c_tci_id) temp
where insDate < sysdate
and temp.c_tci_id not in
(select cst.c_tci_id
from tb_cst_info cst, tb_ins_info ins
where cst.c_tci_id = ins.c_cst_id
)
)
loop
update tb_test1 cst
set cst.C_NO_RELEASE = '0',cst.T_NO_RELEASE_TIME = sysdate, cst.c_stat ='0'
where cst.c_tci_id = thecst.c_tci_id;
--commit;
end loop;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值