/*select c.customer_id    customerid,
       c.customernumber customernumber,
       d.customer_id    debtorid,
       d.customernumber debtornumber
  from customer c, customer d
 where c.debtor_id = d.customer_id
   and c.invoiceaddress_id is null
   and d.invoiceaddress_id is null;*/


update customer c
   set c.invoiceaddress_id = c.visitaddress_id,
       c.systemuser_id     = getminsystemuser(),
       c.timestamp         = sysdate
 where c.customer_id = c.debtor_id
       and c.invoiceaddress_id is null;


begin
execute immediate ('alter table customer add constraint chck_debt_inv_address check ((debtor_id = customer_id and invoiceaddress_id is not null) or (debtor_id <> customer_id));
 ') ;
exception when others then null;
end;
/

