create or replace PROCEDURE BORRADO is
    vTotalDelete NUMBER;
	vCont number:=0;
BEGIN
    begin
        -- inicio proceso, INICIAMOS borrado por TABLA 91, que a fecha de 05/03/2024 no tiene datos migrados
        -- AD74A91T00: Tabla precios de beneficiario
        DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
        delete from AD74A91T00 where usu_alta_91='MIGRADO';
        vTotalDelete :=  SQL%ROWCOUNT;
        DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A91T00, '||vTotalDelete||' registros');
        DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
        commit;
    end;
    BEGIN
        -- AD74A28T00: Tabla de recursos movil emergencia
        DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
        delete from AD74A28T00 where usu_alta_28='MIGRADO';
        vTotalDelete :=  SQL%ROWCOUNT;
        DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A28T00, '||vTotalDelete||' registros');
        DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
        COMMIT;
    END;
    
    BEGIN
        -- AD74A27T00: Tabla de emergencias
        DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A28T00 DISABLE constraint AD74A28T00_FK28';
        delete from AD74A27T00 where usu_alta_27='MIGRADO';
        vTotalDelete :=  SQL%ROWCOUNT;
        DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A27T00, '||vTotalDelete||' registros');
        EXECUTE IMMEDIATE 'ALTER TABLE AD74A28T00 ENABLE constraint AD74A28T00_FK28';
        DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
        COMMIT;
    END;
    
    BEGIN
        -- AD74A25T00: Tabla de intervenciones
        DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
        delete from AD74A25T00 where usu_alta_25='MIGRADO';
        vTotalDelete :=  SQL%ROWCOUNT;
        DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A25T00, '||vTotalDelete||' registros');
        DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
        COMMIT;
    END;
    
    BEGIN
        --- AD74A24T00: Tabla de alarmas
        DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER INDEX IDX_F_ALARMA_24 UNUSABLE';
		EXECUTE IMMEDIATE 'ALTER INDEX IDX_TIPO_FECHA_24 UNUSABLE';
		EXECUTE IMMEDIATE 'ALTER INDEX IDX_ID_TIPO_ALARMA_24 UNUSABLE';
		delete from AD74A24T00 where usu_alta_24='MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;  
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A24T00, '||vTotalDelete||' registros');
        
		EXECUTE IMMEDIATE 'ALTER INDEX IDX_F_ALARMA_24 REBUILD';
		EXECUTE IMMEDIATE 'ALTER INDEX IDX_TIPO_FECHA_24 REBUILD';
		EXECUTE IMMEDIATE 'ALTER INDEX IDX_ID_TIPO_ALARMA_24 REBUILD';
		
        DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
        COMMIT;
    END;

    
	BEGIN
		--- AD74A29T00: Tabla de llamadas
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A24T00 DISABLE constraint AD74A24T00_FK29';   
		delete from AD74A29T00 where usu_alta_29='MIGRADO';
        vTotalDelete :=  SQL%ROWCOUNT;  
        DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A29T00, '||vTotalDelete||' registros');
    	EXECUTE IMMEDIATE 'ALTER TABLE AD74A24T00 ENABLE constraint AD74A24T00_FK29';
    	DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		commit;
	END;
    
	--- AD74A85T00: Tabla de quejas y reclamaciones
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		delete from AD74A85T00 where usu_alta_85='MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;  
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A85T00, '||vTotalDelete||' registros');
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;
	
	--- AD74A90T00 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		delete from AD74A90T00;
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A90T00, '||vTotalDelete||' registros');
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- AE01B01 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		delete from AE01B.AE01B01T00 WHERE USU_ALTA_01 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AEB01.AE01B01T00, '||vTotalDelete||' registros');
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;
	
	--- AE01B00 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		delete from AE01B.AE01B00T00 WHERE USU_ALTA_00 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AE01B.AE01B00T00, '||vTotalDelete||' registros');
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- AE01B05 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		delete from AE01B.AE01B05T00 WHERE USU_ALTA_05 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AE01B.AE01B05T00, '||vTotalDelete||' registros');
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- 89 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		delete from AD74A89T00 WHERE USU_ALTA_89 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AE01B89T00, '||vTotalDelete||' registros');
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- 79 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		delete from AD74A79T00 WHERE USU_ALTA_79 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A79T00, '||vTotalDelete||' registros');
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;
	
	--- 03 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		delete from AD74A03T00 WHERE USU_ALTA_03 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A03T00, '||vTotalDelete||' registros');
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- 82 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		DELETE FROM AD74A82T00 WHERE  EXISTS(SELECT ID_INF_SOCIAL_02 FROM AD74A02T00 WHERE USU_ALTA_02 = 'MIGRADO');
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A82T00, '||vTotalDelete||' registros');
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- 02 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 DISABLE constraint AD74A01T00_FK02';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A82T00 DISABLE constraint AD74A82T00_FK02';   
		
		DELETE FROM AD74A02T00 WHERE USU_ALTA_02 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A02T00, '||vTotalDelete||' registros');
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 ENABLE constraint AD74A01T00_FK02';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A82T00 ENABLE constraint AD74A82T00_FK02';   
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- 16 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A02T00 DISABLE constraint AD74A02T00_FK16';    
    
		DELETE FROM AD74A16T00 WHERE USU_ALTA_16 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A16T00, '||vTotalDelete||' registros');
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A02T00 ENABLE constraint AD74A02T00_FK16';   
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;
	
	--- 00 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A78T00 DISABLE constraint AD74A78T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A85T00 DISABLE constraint AD74A85T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A04T00 DISABLE constraint AD74A04T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A03T00 DISABLE constraint AD74A03T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A19T00 DISABLE constraint AD74A19T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A13T00 DISABLE constraint AD74A13T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A10T00 DISABLE constraint AD74A10T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A16T00 DISABLE constraint AD74A16T00_FK00';   
		
		DELETE FROM AD74A78T00 WHERE ID_EXPEDIENTE_78 IN (SELECT ID_EXPEDIENTE_00 FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO');
		DELETE FROM AD74A85T00 WHERE ID_EXPEDIENTE_85 IN (SELECT ID_EXPEDIENTE_00 FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO');
		DELETE FROM AD74A04T00 WHERE ID_EXPEDIENTE_04 IN (SELECT ID_EXPEDIENTE_00 FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO');
		DELETE FROM AD74A03T00 WHERE ID_EXPEDIENTE_03 IN (SELECT ID_EXPEDIENTE_00 FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO');
		DELETE FROM AD74A19T00 WHERE ID_EXPEDIENTE_19 IN (SELECT ID_EXPEDIENTE_00 FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO');
		DELETE FROM AD74A13T00 WHERE ID_EXPEDIENTE_13 IN (SELECT ID_EXPEDIENTE_00 FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO');
		DELETE from ad74a11t00 WHERE ID_TRAMITE_EXP_11 IN (SELECT ID_TRAMITE_EXP_10 FROM AD74A10T00 WHERE ID_EXPEDIENTE_10 IN (SELECT ID_EXPEDIENTE_00 FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO'));
		DELETE FROM AD74A10T00 WHERE ID_EXPEDIENTE_10 IN (SELECT ID_EXPEDIENTE_00 FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO');
		DELETE FROM AD74A16T00 WHERE ID_EXPEDIENTE_16 IN (SELECT ID_EXPEDIENTE_00 FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO');
		
		DELETE FROM AD74A00T00 WHERE USU_ALTA_00 = 'MIGRADO';
		
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A00T00, '||vTotalDelete||' registros');
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A78T00 ENABLE constraint AD74A78T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A85T00 ENABLE constraint AD74A85T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A04T00 ENABLE constraint AD74A04T00_FK00';   
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A03T00 ENABLE constraint AD74A03T00_FK00';     
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A19T00 ENABLE constraint AD74A19T00_FK00';  
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A13T00 ENABLE constraint AD74A13T00_FK00';  
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A10T00 ENABLE constraint AD74A10T00_FK00';  
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A16T00 ENABLE constraint AD74A16T00_FK00';  

		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;
	
	--- 04 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
    
		DELETE FROM AD74A04T00 WHERE USU_ALTA_04 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A04T00, '||vTotalDelete||' registros');

		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- 23 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
    
		DELETE FROM AD74A23T00 WHERE USU_ALTA_23 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A23T00, '||vTotalDelete||' registros');

		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;
	
	--- 01 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A71T00 DISABLE constraint AD74A71T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A27T00 DISABLE constraint AD74A27T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A89T00 DISABLE constraint AD74A89T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A22T00 DISABLE constraint AD74A22T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A26T00 DISABLE constraint AD74A26T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A25T00 DISABLE constraint AD74A25T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A24T00 DISABLE constraint AD74A24T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A20T00 DISABLE constraint AD74A20T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A21T00 DISABLE constraint AD74A21T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A23T00 DISABLE constraint AD74A23T00_FK01';		
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 DISABLE constraint AD74A00T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A04T00 DISABLE constraint AD74A04T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A16T00 DISABLE constraint AD74A16T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A03T00 DISABLE constraint AD74A03T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A75T00 DISABLE constraint AD74A75T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A84T00 DISABLE constraint AD74A84T00_FK01';		
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A85T00 DISABLE constraint AD74A85T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A86T00 DISABLE constraint AD74A86T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A91T00 DISABLE constraint AD74A91T00_FK01';
		DELETE FROM AD74A71T00 WHERE ID_SOLICITANTE_71 IN (SELECT ID_SOLICITANTE_01 FROM AD74A01T00 WHERE USU_ALTA_01 = 'MIGRADO');
		DELETE FROM AD74A28T00 WHERE ID_EMERGENCIA_28 IN (SELECT ID_EMERGENCIA_27 FROM AD74A27T00 WHERE ID_SOLICITANTE_27 IN (SELECT ID_SOLICITANTE_01 FROM AD74A01T00 WHERE USU_ALTA_01 = 'MIGRADO'));
		DELETE FROM AD74A27T00 WHERE ID_SOLICITANTE_27 IN (SELECT ID_SOLICITANTE_01 FROM AD74A01T00 WHERE USU_ALTA_01 = 'MIGRADO');
		DELETE FROM AD74A89T00 WHERE ID_SOLICITANTE_89 IN (SELECT ID_SOLICITANTE_01 FROM AD74A01T00 WHERE USU_ALTA_01 = 'MIGRADO');
		DELETE FROM AD74A85T00 WHERE ID_SOLICITANTE_85 IN (SELECT ID_SOLICITANTE_01 FROM AD74A01T00 WHERE USU_ALTA_01 = 'MIGRADO');
		DELETE FROM AD74A70T00 WHERE ID_AVISO_70 IN (SELECT ID_AVISO_20 FROM AD74A20T00 WHERE ID_SOLICITANTE_20 IN (SELECT ID_SOLICITANTE_01 FROM AD74A01T00 WHERE USU_ALTA_01 = 'MIGRADO'));
		DELETE FROM AD74A20T00 WHERE ID_SOLICITANTE_20 IN (SELECT ID_SOLICITANTE_01 FROM AD74A01T00 WHERE USU_ALTA_01 = 'MIGRADO');
		UPDATE AD74A00T00 SET ID_SOLICITANTE_00  =NULL WHERE ID_SOLICITANTE_00 NOT IN (SELECT ID_SOLICITANTE_01 FROM AD74A01T00 WHERE USU_ALTA_01 = 'MIGRADO');
		DELETE FROM AD74A01T00 WHERE USU_ALTA_01 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A01T00, '||vTotalDelete||' registros');
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A71T00 ENABLE constraint AD74A71T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A27T00 ENABLE constraint AD74A27T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A89T00 ENABLE constraint AD74A89T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A22T00 ENABLE constraint AD74A22T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A26T00 ENABLE constraint AD74A26T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A25T00 ENABLE constraint AD74A25T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A24T00 ENABLE constraint AD74A24T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A20T00 ENABLE constraint AD74A20T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A23T00 ENABLE constraint AD74A23T00_FK01';		
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 ENABLE constraint AD74A00T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A04T00 ENABLE constraint AD74A04T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A16T00 ENABLE constraint AD74A16T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A03T00 ENABLE constraint AD74A03T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A75T00 ENABLE constraint AD74A75T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A84T00 ENABLE constraint AD74A84T00_FK01';		
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A85T00 ENABLE constraint AD74A85T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A86T00 ENABLE constraint AD74A86T00_FK01';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A91T00 ENABLE constraint AD74A91T00_FK01';
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;
	
	--- 08 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 DISABLE constraint AD74A01T00_FK08';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A09T00 DISABLE constraint AD74A09T00_FK08';
		
    
		DELETE FROM AD74A08T00 WHERE USU_ALTA_08 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A08T00, '||vTotalDelete||' registros');
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 ENABLE constraint AD74A01T00_FK08';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A09T00 ENABLE constraint AD74A09T00_FK08';
   
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- 05 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 DISABLE constraint AD74A01T00_FK05';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 DISABLE constraint AD74A00T00_FK05';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A87T00 DISABLE constraint AD74A87T00_FK05';
		DELETE  FROM AD74A87T00 WHERE ID_CUENTA_87 IN (SELECT ID_CUENTA_05 FROM AD74A05T00 WHERE USU_ALTA_05 = 'MIGRADO' );
		DELETE FROM AD74A05T00 WHERE USU_ALTA_05 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A05T00, '||vTotalDelete||' registros');
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 ENABLE constraint AD74A01T00_FK05';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 ENABLE constraint AD74A00T00_FK05';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A87T00 ENABLE constraint AD74A87T00_FK05';
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;


	--- 07 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 DISABLE constraint AD74A01T00_FK07';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 DISABLE constraint AD74A00T00_FK07';
		UPDATE AD74A00T00 SET ID_PERFIL_00 = NULL WHERE ID_PERFIL_00 IN (SELECT ID_PERFIL_07 FROM AD74A07T00  WHERE USU_ALTA_07 = 'MIGRADO');
		DELETE FROM AD74A07T00 WHERE USU_ALTA_07 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A07T00, '||vTotalDelete||' registros');
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 ENABLE constraint AD74A01T00_FK07';	
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 ENABLE constraint AD74A00T00_FK07';
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;

	--- 06 ----------------------------------
	BEGIN
		DBMS_OUTPUT.PUT_LINE('INICIO: '||SYSDATE);
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 DISABLE constraint AD74A01T00_FK06';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A32T00 DISABLE constraint AD74A32T00_FK06';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 DISABLE constraint AD74A00T00_FK06';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 DISABLE constraint AD74A00T00_FK06_2';
    
		UPDATE AD74A00T00 SET id_direccion_00 = NULL WHERE id_direccion_00 IN (SELECT id_direccion_06 FROM AD74A06T00  WHERE USU_ALTA_06 = 'MIGRADO');
		UPDATE AD74A00T00 SET ID_DIRECCION_NOTIF_00 = NULL WHERE ID_DIRECCION_NOTIF_00 IN (SELECT id_direccion_06 FROM AD74A06T00 WHERE USU_ALTA_06 = 'MIGRADO');
   
		DELETE FROM AD74A06T00 WHERE USU_ALTA_06 = 'MIGRADO';
		vTotalDelete :=  SQL%ROWCOUNT;
		DBMS_OUTPUT.PUT_LINE('BORRADOS AD74A06T00, '||vTotalDelete||' registros');
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A01T00 ENABLE constraint AD74A01T00_FK06';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A32T00 ENABLE constraint AD74A32T00_FK06';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 ENABLE constraint AD74A00T00_FK06';
		EXECUTE IMMEDIATE 'ALTER TABLE AD74A00T00 ENABLE constraint AD74A00T00_FK06_2';
		DBMS_OUTPUT.PUT_LINE('FIN: '||SYSDATE);
		COMMIT;
	END;
end BORRADO;

/