declare
cursor cur is
SELECT * FROM
(
SELECT A.*, ROWNUM RN
FROM (
select d.tbbm,i.inventoryid,i.chmc,i.jgbs,i.zhbs,i.chlx,i.createtime
from s_product_detail d,s_inventory i
where d.inventoryid=i.inventoryid and i.active=1 and d.tbbm is not null and i.chlx in (1,2)
and i.inventoryid not in (
select distinct(dd.inventoryid) from s_product_plan_detail dd where dd.productplansaletypeid in (
select st.productplansaletypeid from s_product_plan_sale_type st
where to_char(xsrq,'yyyy-MM-dd')>='2018-06-01'))
order by i.createtime
) A
-- 删除的数量
WHERE ROWNUM <= 5
)
WHERE RN >= 0;
begin
dbms_output.enable(1000000);
for r in cur
loop
dbms_output.put_line('inventoryId='||r.inventoryId||' tbbm='||r.tbbm||' name='||r.chmc||' tenantId='||r.zhbs||' orgId='||r.jgbs||' type='||r.chlx);
-- 把标记置位0
update s_inventory i set active=0 where i.inventoryid=r.inventoryId;
-- 清空同步编码
update s_product_detail set tbbm=null where inventoryid=r.inventoryId;
-- 插入回收表
insert into s_inventory_sync_code_recovery(inventorysynccoderecoveryid,tenantid,hsbm,active)
values(sys_guid(),r.zhbs,r.tbbm,1);
end loop;
commit;
exception
when others then
rollback;
dbms_output.put_line('code:' || sqlcode);
dbms_output.put_line('errm:' || sqlerrm);
raise;
end;