
-- eseguire come utente MNP 
-------------------------------------------------------------------------

ALTER TABLE MNP_GESTIONE_RICHIESTA_REC_EXT add(
	CODICE_ORDINE VARCHAR2(15),
	TIPO_OPERAZIONE VARCHAR2(3)
	);
	
ALTER TABLE MNP_MSP_IN_REC add(
	CODICE_ORDINE VARCHAR2(15),
	SUBSYS				VARCHAR2(10)
	);
	
ALTER TABLE MNP_MSP_SCARTI_IN add(
	CODICE_ORDINE VARCHAR2(15),
	SUBSYS				VARCHAR2(10)
	);
	
ALTER TABLE MNP_DBCGO_NOTIFICA_REC_OUT add(
	CODICE_ORDINE VARCHAR2(15),
	TIPO_OPERAZIONE VARCHAR2(3)
	);
	

 ---------------- inizio HZ_CCRM_OUT

CREATE TABLE HZ_CCRM_OUT
(
  UNIQUE_ID             					NUMBER       					 			 NOT NULL,
  DA_SCODARE            					NUMBER(1)  	DEFAULT 0  			 NOT NULL,
  DATA_INVIO           						DATE				DEFAULT SYSDATE  NOT NULL,
  ID_RICHIESTA          					NUMBER       								 NOT NULL,
  DIRECTORY_NUMBER      					VARCHAR2(12)					  		 NOT NULL,
  CODICE_EVENTO										VARCHAR2(2)  					 			 NOT NULL,
  MSISDN                 					VARCHAR2(13) 					 			 NOT NULL
)
TABLESPACE TAB_HUGE;


ALTER TABLE HZ_CCRM_OUT 
ADD CONSTRAINT PK_HZ_CCRM_OUT PRIMARY KEY(UNIQUE_ID)
USING INDEX 
TABLESPACE TAB_IDX_BIG
ENABLE
VALIDATE;

ALTER TABLE HZ_CCRM_OUT ADD (
CONSTRAINT FK_HZ_CCRM_OUT  
FOREIGN KEY (ID_RICHIESTA) 
REFERENCES HZ_GESTIONE_RICHIESTA (ID_RICHIESTA));

----------------fine HZ_CCRM_OUT   ---------------------

----------------inizio MNP_RECOVERY_OUT ----------------

CREATE TABLE MNP_RECOVERY_OUT
(
	RECOVERY_TYPE										NUMBER(2)									NOT NULL,	
	UNIQUE_ID												NUMBER										NOT NULL,
	MESSAGE_ID											VARCHAR2(50),		
	STATO_MESSAGGIO									NUMBER(2) 		DEFAULT 0,
	DATA_INSERIMENTO								DATE					DEFAULT SYSDATE,
	DATA_ULTIMO_AGGIORNAMENTO				DATE 					DEFAULT SYSDATE,
	ECCEZIONE_AVVENUTA							VARCHAR2(1000),
	REDELIVERY_COUNT								NUMBER(3) 		DEFAULT 1
)
TABLESPACE TAB_HUGE;

ALTER TABLE MNP_RECOVERY_OUT 
ADD CONSTRAINT PK_MNP_RECOVERY_OUT PRIMARY KEY(UNIQUE_ID,RECOVERY_TYPE)
USING INDEX 
TABLESPACE TAB_IDX_BIG
ENABLE
VALIDATE;

----------------fine MNP_RECOVERY_OUT ------------------

-- SEQUENCE
CREATE SEQUENCE SEQ_HZ_CCRM_OUT
MAXVALUE 9223372036854775807
;

-- TRIGGER
CREATE OR REPLACE TRIGGER t_SEQ_HZ_CCRM_OUT
before insert on HZ_CCRM_OUT for each row
begin
  SELECT SEQ_HZ_CCRM_OUT.nextval INTO :new.UNIQUE_ID FROM dual;
end;
/
