huxiangbin82gf
2021-01-22 09:25oracle游标变量增加判断条件
declare
cursor c is
select o.store astore,o.adate adate,o.gdgid gdgid,-sum(outbuyqty+outwsaleqty+outbuybckqty+outwsalebckqty) dq,
-sum(outbuyamt+outwsaleamt+outbuybckamt+outwsalebckamt) dt,-sum(outbuycost+outwsalecost+outbuybckcost+outwsalebckcost) di,
(case when p.store is not null then 1 else 0 end) prm,rtrim(g.sort) sort from std_jxcdrpt o
left join V_VENDORSUMDIFF_GXLH p on o.store= p.store and o.adate= p.begindate and o.gdgid= p.gdgid
left join goods g on o.gdgid= g.gid
where o.adate>='2021.01.20'
group by o.store,o.adate,o.gdgid,p.store,g.sort;
begin
for r in c loop
/*
if substr(r.sort,1,1) = '1'
then
substr(r.sort,1,4)
else if substr(r.sort,1,1) = '2'
then
if substr(r.sort,1,4) not in ('2002','2206','2208') then
substr(r.sort,1,4)
else
if substr(r.sort,1,4) in ('2002','2206') then
substr(r.sort,1,6)
else if substr(r.sort,1,1) = '3' or substr(r.sort,1,1) = '8'
then
substr(r.sort,1,2)
end if;
*/
select kd,tkd from yn_kd where code =(
if substr(r.sort,1,1) = '1'
then
substr(r.sort,1,4)
else if substr(r.sort,1,1) = '2'
then
if substr(r.sort,1,4) not in ('2002','2206','2208') then
substr(r.sort,1,4)
else
if substr(r.sort,1,4) in ('2002','2206') then
substr(r.sort,1,6)
else if substr(r.sort,1,1) = '3' or substr(r.sort,1,1) = '8'
then
substr(r.sort,1,2)
end if;)
if r.prm = 0 then
insert into mnfran
select r.astore,r.adate,r.gdgid,sort,kd,r.dq,r.dt,r.di,r.dt*kd,r.prm,0 from dual;
else
insert into mnfran
select r.astore,r.adate,r.gdgid,sort,r.tkd,r.dq,r.dt,r.di,r.dt*r.tkd,r.prm,0 from DUAL;
end if;
end loop;
end;
- 点赞
- 回答
- 收藏
- 复制链接分享
0条回答
为你推荐
- oracle 测试存储过程,执行一次,上次的返回结果便累加上去,如何清除?
- sql
- oracle
- 1个回答
- 请问使用游标处理动态sql的时候出现长度超长的问题如何解决?
- sql
- oracle
- 3个回答
- Oralce11g创建过程,Java调用问题
- 数据库
- oracle
- 0个回答
- oracle 定义一个函数报错了
- 数据库
- oracle
- 0个回答
- PreparedStatement 预编译原理
- 企业应用
- 0个回答