CREATE OR REPLACE procedure "DBCGO"."RECUPERO_DATI_DBCGO"  IS

n_rec integer := 0;

CURSOR cur_recipient is
  SELECT ric_rec.ID_RICHIESTA  AS idRichiesta,
         ric_rec.CODICE_OPERATORE_DON_EFF AS donorEffettivo,
         ric_rec.CODICE_OPERATORE_Donating AS donating
  FROM   mnp.MNP_GESTIONE_RICHIESTA_REC@mnp ric_rec 
  WHERE  ric_rec.ID_RICHIESTA IN
  (
  '100000000016131405',
'100000000016627720',
'100000000016627726',
'100000000016627740',
'100000000016627757',
'100000000016627763',
'100000000016627801',
'100000000016627838',
'100000000016627856',
'100000000016627870',
'100000000016627882',
'100000000016627903',
'100000000016627906',
'100000000016627924',
'100000000016628044',
'100000000016628202',
'100000000016628646',
'100000000016628790',
'100000000016628963',
'100000000016628964',
'100000000016628965',
'100000000016628966',
'100000000016628968',
'100000000016628978',
'100000000016628979',
'100000000016628980',
'100000000016628981',
'100000000016628982',
'100000000016628983',
'100000000016628984',
'100000000016628985',
'100000000016629015',
'100000000016629016',
'100000000016629017',
'100000000016629018',
'100000000016629019',
'100000000016629020',
'100000000016629021',
'100000000016629023',
'100000000016629578',
'100000000016630795',
'100000000016631043',
'100000000016631539',
'100000000016631594',
'100000000016631612',
'100000000016631639',
'100000000016631786',
'100000000016631871',
'100000000016631962',
'100000000016631990',
'100000000016632070',
'100000000016632384',
'100000000016632428',
'100000000016632483',
'100000000016632562',
'100000000016632576',
'100000000016632623',
'100000000016632689',
'100000000016632693',
'100000000016632710',
'100000000016632722',
'100000000016632729',
'100000000016632783',
'100000000016632836',
'100000000016632951',
'100000000016633009',
'100000000016633028',
'100000000016633059',
'100000000016633073',
'100000000016633288',
'100000000016633300',
'100000000016633376',
'100000000016633427',
'100000000016633461',
'100000000016633491',
'100000000016633620',
'100000000016633628',
'100000000016633634',
'100000000016633646',
'100000000016642436',
'100000000016642437',
'100000000016642438',
'200000000016628527',
'200000000016629615',
'200000000016629827',
'200000000016629828',
'200000000016629840',
'200000000016629845',
'200000000016629849',
'200000000016629888',
'200000000016629891',
'200000000016629936',
'200000000016629954',
'200000000016629971',
'200000000016630067',
'200000000016630135',
'200000000016630441',
'200000000016630461',
'200000000016630517',
'200000000016630794',
'200000000016630796',
'200000000016630797',
'200000000016630819',
'200000000016631726',
'200000000016632879',
'200000000016632896',
'W00000000016630996',
'W00000000016631246',
'W00000000016631254',
'W00000000016631301',
'W00000000016631411',
'W00000000016632875',
'W00000000016633083',
'W00000000016633161',
'W00000000016633236'
  );

BEGIN

DBMS_OUTPUT.put_line ('recupero_dati_DBCGO: INIZIO PROCEDURA  - '||TO_CHAR(sysdate,'YYYY-MM-DD HH24:MI:SS'));



  FOR rec IN cur_recipient LOOP
    BEGIN
      n_rec := n_rec +1;
  -- Aggiorno solo se sono in presenza di operatore donor virtuale
     IF rec.donorEffettivo <> rec.donating
        THEN
          UPDATE DBCGO.DBCGO_GESTIONE_RICHIESTA_REC go_rec
            SET go_rec.CODICE_OPERATORE_V_DONOR = rec.donorEffettivo
          WHERE go_rec.ID_RICHIESTA = rec.idRichiesta AND
                go_rec.CODICE_OPERATORE_V_DONOR IS NULL;
     END IF;
    END;
  END LOOP;

  COMMIT;

DBMS_OUTPUT.put_line ('recupero_dati_DBCGO:  FINE  PROCEDURA - '||' RECORDS TRATTATI: '||n_rec);
EXCEPTION
   WHEN OTHERS
   THEN
    if cur_recipient%ISOPEN then CLOSE cur_recipient;
    end if;
    DBMS_OUTPUT.put_line ('Errore in recupero_dati_DBCGO ' || SQLERRM||' - '||to_char(sysdate,'YYYY-MM-DD HH24:MI:SS'));
    RETURN;

END; 
/