--------------------------------------------------------
--  DDL for Procedure P_ELIMINAR_SOLICITUD
--------------------------------------------------------
set define off;

  CREATE OR REPLACE EDITIONABLE PROCEDURE "ENVX_OPER"."P_ELIMINAR_SOLICITUD" (pi_id_request IN NUMBER)
AS

v_aux NUMBER := 0;

BEGIN

  --Proceso para eliminar 1 solicitud de despliegue completa--

	--Eliminar los objetos del request--
	delete from deployment_req_object where id_request = pi_id_request;
	commit;

	--Eliminar los ambientes del request--
	delete from deployment_req_env where id_request = pi_id_request;
	commit;

	--Eliminar los grupos del request--
	delete from deployment_req_hgroup where id_request = pi_id_request;
	commit;

	--Eliminar los tickets del request--
	delete from deployment_req_reference where id_request = pi_id_request;
	commit;

	--Eliminar los queue del request--
	delete from deployment_request_queue where id_request = pi_id_request;
	commit;

	--Eliminar el historial de ejecucion del request--
	FOR i IN (select * from request_exec_deploy ed where ed.id_request = pi_id_request) LOOP
		delete from request_exec_deploy where id_control_deploy = i.id_control_deploy;
		v_aux := v_aux + 1;
		IF v_aux = 100 THEN
			commit;
			v_aux := 0;
		END IF;
	END LOOP;
	v_aux := 0;
	commit;

	--Eliminar el historial de flow del request--
	FOR h IN (select * from request_exec_flow ef where ef.id_request = pi_id_request) LOOP
		delete from request_exec_flow where id_request = h.id_request;
		v_aux := v_aux + 1;
		IF v_aux = 100 THEN
			commit;
			v_aux := 0;
		END IF;
	END LOOP;	
	v_aux := 0;
	commit;

	--Eliminar los request--
	delete from deployment_request where id_request = pi_id_request;
	commit;

  --Proceso para eliminar 1 solicitud de despliegue completa--

END;

/
