--1、备份
create table cux_ab20180330 as select * from ap_batches_all;
--2、更新
update ap_batches_all ab
set ab.org_id=(select aia.org_id from ap_invoices_all aia where aia.batch_id=ab.batch_id and rownum<=1);
--3、删除空批
delete ap_batches_all ab where not exists (select 1 from ap_invoices_all aia where aia.batch_id=ab.batch_id);
--4、查询空ORG_ID
select ab.org_id,ab.batch_id from ap_batches_all ab where ab.org_id is null;
--5、查询空批
select * from ap_batches_all ab where not exists (select 1 from ap_invoices_all aia where aia.batch_id=ab.batch_id);