--
-- Create Schema Script
--   Database Version            : 12.2.0.1.0
--   Database Compatible Level   : 12.2.0.0.0
--   Script Compatible Level     : 12.2.0.0.0
--   Toad Version                : 13.3.0.181
--   DB Connect String           : 10.140.209.52:1521/XE
--   Schema                      : BANDO_VOLI
--   Script Created by           : BANDO_VOLI
--   Script Created at           : 09/03/2026 17:15:43
--   Notes                       : 
--

-- Object Counts: 
--   Functions: 9       Lines of Code: 356 
--   Indexes: 62        Columns: 67         
--   Procedures: 11     Lines of Code: 259 
--   Sequences: 23 
--   Tables: 24         Columns: 228        Constraints: 81     
--   Triggers: 20 
--   Views: 2           Columns: 42         


-- "Set define off" turns off substitution variables.
Set define off; 

--
-- ACCOUNT_ANAG_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE ACCOUNT_ANAG_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 200
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- ACCOUNT_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE ACCOUNT_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- ACCOUNT_NUCLEO_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE ACCOUNT_NUCLEO_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- ALLEGATI_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE ALLEGATI_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- ANAG_COMPAGNIE_SEQ  (Sequence) 
--
CREATE SEQUENCE ANAG_COMPAGNIE_SEQ
  START WITH 81
  MAXVALUE 999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- ANAG_DICHIARAZIONI_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE ANAG_DICHIARAZIONI_ID_SEQ
  START WITH 21
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- BANDI_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE BANDI_ID_SEQ
  START WITH 21
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- COMPAGNIE_SEQ  (Sequence) 
--
CREATE SEQUENCE COMPAGNIE_SEQ
  START WITH 101
  MAXVALUE 999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- COMUNE_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE COMUNE_ID_SEQ
  START WITH 21121
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- DOCUMENTIBANDO_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE DOCUMENTIBANDO_ID_SEQ
  START WITH 21
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- DOMANDA_CONTRATTI_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE DOMANDA_CONTRATTI_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- DOMANDA_EMAIL_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE DOMANDA_EMAIL_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- DOMANDA_IBAN_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE DOMANDA_IBAN_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- DOMANDA_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE DOMANDA_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- DOMANDA_SCONTI_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE DOMANDA_SCONTI_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- ESPORTAZIONI_SEQ  (Sequence) 
--
CREATE SEQUENCE ESPORTAZIONI_SEQ
  START WITH 81
  MAXVALUE 999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- FAQ_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE FAQ_ID_SEQ
  START WITH 21
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- FAQ_UTENTI_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE FAQ_UTENTI_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- LOGS_BE_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE LOGS_BE_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 200
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- LOGS_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE LOGS_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- LOGS_P7M_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE LOGS_P7M_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- SPID_ACCESSI_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE SPID_ACCESSI_ID_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- UID_FIREBASE_ADMIN_ID_SEQ  (Sequence) 
--
CREATE SEQUENCE UID_FIREBASE_ADMIN_ID_SEQ
  START WITH 81
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER
  NOKEEP
  NOSCALE
  GLOBAL;


--
-- ACCOUNT  (Table) 
--
--   Row Count: 3762
CREATE TABLE ACCOUNT
(
  CODICE_FISCALE              VARCHAR2(16 BYTE) NOT NULL,
  USERNAME                    VARCHAR2(255 BYTE),
  PASSWORD                    VARCHAR2(255 BYTE),
  DATA_REGISTRAZIONE          TIMESTAMP(6)      DEFAULT SYSTIMESTAMP,
  AUTORIZZAZIONE_TRATTAMENTO  NUMBER            DEFAULT NULL,
  CANCELLATO                  NUMBER            DEFAULT 0,
  ID                          NUMBER            NOT NULL
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- IX_CF_ACCOUNT  (Index) 
--
--  Dependencies: 
--   ACCOUNT (Table)
--
CREATE UNIQUE INDEX IX_CF_ACCOUNT ON ACCOUNT
(CODICE_FISCALE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );
--
-- PK_ACCOUNT_ID  (Index) 
--
--  Dependencies: 
--   ACCOUNT (Table)
--
CREATE UNIQUE INDEX PK_ACCOUNT_ID ON ACCOUNT
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE ACCOUNT ADD (
  CONSTRAINT PK_ACCOUNT_ID
  PRIMARY KEY
  (ID)
  USING INDEX PK_ACCOUNT_ID
  ENABLE VALIDATE);



--
-- ACCOUNT_ANAGRAFICA  (Table) 
--
--   Row Count: 3762
CREATE TABLE ACCOUNT_ANAGRAFICA
(
  CODICE_FISCALE            VARCHAR2(16 BYTE)   NOT NULL,
  NOME                      VARCHAR2(200 BYTE),
  COGNOME                   VARCHAR2(200 BYTE),
  DATA_NASCITA              VARCHAR2(20 BYTE),
  COMUNE_NASCITA            VARCHAR2(200 BYTE),
  PROV_NASCITA              VARCHAR2(2 BYTE),
  CAP_NASCITA               VARCHAR2(5 BYTE),
  COMUNE_RESIDENZA          VARCHAR2(200 BYTE),
  PROV_RESIDENZA            VARCHAR2(2 BYTE),
  CAP_RESIDENZA             VARCHAR2(5 BYTE),
  INDIRIZZO_RESIDENZA       VARCHAR2(200 BYTE),
  CIVICO_RESIDENZA          VARCHAR2(20 BYTE),
  SPID_CELLULARE            VARCHAR2(200 BYTE),
  SPID_DOCUMENTO            VARCHAR2(200 BYTE),
  SPID_DOCUMENTO_SCADENZA   VARCHAR2(200 BYTE),
  SPID_DOCUMENTO_RILASCIO   VARCHAR2(200 BYTE),
  SPID_TIPO_DOCUMENTO       VARCHAR2(200 BYTE),
  SPID_DOCUMENTO_ENTE       VARCHAR2(200 BYTE),
  DATA_REGISTRAZIONE        TIMESTAMP(6)        DEFAULT SYSTIMESTAMP,
  DATA_MODIFICA             TIMESTAMP(6),
  ID                        NUMBER              NOT NULL,
  RECAPITO                  VARCHAR2(50 BYTE),
  SESSO                     VARCHAR2(1 BYTE),
  FORZATURA_CODICE_FISCALE  INTEGER             DEFAULT 0,
  SPID_EMAIL                VARCHAR2(200 BYTE),
  PEC                       VARCHAR2(200 BYTE),
  EMAIL                     VARCHAR2(255 BYTE)
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- ACCOUNT_ANAGRAFICA_PK  (Index) 
--
--  Dependencies: 
--   ACCOUNT_ANAGRAFICA (Table)
--
CREATE UNIQUE INDEX ACCOUNT_ANAGRAFICA_PK ON ACCOUNT_ANAGRAFICA
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE ACCOUNT_ANAGRAFICA ADD (
  CONSTRAINT ACCOUNT_ANAGRAFICA_PK
  PRIMARY KEY
  (ID)
  USING INDEX ACCOUNT_ANAGRAFICA_PK
  ENABLE VALIDATE);



--
-- ACCOUNT_NUCLEO_FAMILIARE  (Table) 
--
--  Dependencies: 
--   ACCOUNT (Table)
--
--   Row Count: 3775
CREATE TABLE ACCOUNT_NUCLEO_FAMILIARE
(
  ID                  INTEGER                   NOT NULL,
  ID_ACCOUNT          NUMBER,
  COGNOME             VARCHAR2(255 BYTE),
  NOME                VARCHAR2(255 BYTE),
  DATA_NASCITA        DATE,
  RAPPORTO_PARENTELA  INTEGER                   NOT NULL,
  CODICE_FISCALE      VARCHAR2(255 BYTE)        NOT NULL,
  CONFERMATO          INTEGER                   DEFAULT 0,
  COMUNE_RESIDENZA    VARCHAR2(255 BYTE),
  PROV_RESIDENZA      VARCHAR2(2 BYTE),
  CAP_RESIDENZA       VARCHAR2(5 BYTE),
  FLAG                VARCHAR2(1000 BYTE),
  PRIORITY            INTEGER                   DEFAULT 0
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- ACCOUNT_NUCLEO_FAMILIARE_PK  (Index) 
--
--  Dependencies: 
--   ACCOUNT_NUCLEO_FAMILIARE (Table)
--
CREATE UNIQUE INDEX ACCOUNT_NUCLEO_FAMILIARE_PK ON ACCOUNT_NUCLEO_FAMILIARE
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );
--
-- IDX_ACCOUNT_CODICE_FISCALE  (Index) 
--
--  Dependencies: 
--   ACCOUNT_NUCLEO_FAMILIARE (Table)
--
CREATE UNIQUE INDEX IDX_ACCOUNT_CODICE_FISCALE ON ACCOUNT_NUCLEO_FAMILIARE
(ID_ACCOUNT, CODICE_FISCALE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE ACCOUNT_NUCLEO_FAMILIARE ADD (
  CONSTRAINT ACCOUNT_NUCLEO_FAMILIARE_PK
  PRIMARY KEY
  (ID)
  USING INDEX ACCOUNT_NUCLEO_FAMILIARE_PK
  ENABLE VALIDATE);



--
-- AEROPORTI  (Table) 
--
--   Row Count: 11
CREATE TABLE AEROPORTI
(
  CODICE   VARCHAR2(3 BYTE)                     NOT NULL,
  NOME     VARCHAR2(255 BYTE)                   NOT NULL,
  REGIONE  NUMBER                               NOT NULL
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- AEROPORTI_PK  (Index) 
--
--  Dependencies: 
--   AEROPORTI (Table)
--
CREATE UNIQUE INDEX AEROPORTI_PK ON AEROPORTI
(CODICE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE AEROPORTI ADD (
  CONSTRAINT AEROPORTI_PK
  PRIMARY KEY
  (CODICE)
  USING INDEX AEROPORTI_PK
  ENABLE VALIDATE);



--
-- ALGPARAMETERS  (Table) 
--
--   Row Count: 2
CREATE TABLE ALGPARAMETERS
(
  NAME   VARCHAR2(100 BYTE),
  VALUE  NVARCHAR2(100)
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- ALLEGATI  (Table) 
--
--   Row Count: 3752
CREATE TABLE ALLEGATI
(
  ID                  INTEGER                   NOT NULL,
  ID_DOMANDA          INTEGER,
  FILEPATH            VARCHAR2(1000 BYTE),
  CANCELLATO          INTEGER,
  ID_DOCUMENTO        NUMBER,
  TIPO_DOCUMENTO      NUMBER                    DEFAULT 0,
  FILESIZE            NUMBER,
  DATA_REGISTRAZIONE  TIMESTAMP(6)              DEFAULT SYSTIMESTAMP,
  NOTE                VARCHAR2(200 BYTE),
  NOMEFILEORIGINALE   VARCHAR2(255 BYTE),
  HASH_FILE           VARCHAR2(1000 BYTE)
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- ALLEGATI_PK  (Index) 
--
--  Dependencies: 
--   ALLEGATI (Table)
--
CREATE UNIQUE INDEX ALLEGATI_PK ON ALLEGATI
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE ALLEGATI ADD (
  CONSTRAINT ALLEGATI_PK
  PRIMARY KEY
  (ID)
  USING INDEX ALLEGATI_PK
  ENABLE VALIDATE);



--
-- ANAG_COMPAGNIE  (Table) 
--
--   Row Count: 46
CREATE TABLE ANAG_COMPAGNIE
(
  ID             INTEGER                        NOT NULL,
  NOME           VARCHAR2(255 BYTE)             NOT NULL,
  ADESIONE       INTEGER                        DEFAULT 0                     NOT NULL,
  DATA_ADESIONE  DATE
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- ANAG_COMPAGNIE_PK  (Index) 
--
--  Dependencies: 
--   ANAG_COMPAGNIE (Table)
--
CREATE UNIQUE INDEX ANAG_COMPAGNIE_PK ON ANAG_COMPAGNIE
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE ANAG_COMPAGNIE ADD (
  CONSTRAINT ANAG_COMPAGNIE_PK
  PRIMARY KEY
  (ID)
  USING INDEX ANAG_COMPAGNIE_PK
  ENABLE VALIDATE);



--
-- ANAG_DICHIARAZIONI  (Table) 
--
--   Row Count: 0
CREATE TABLE ANAG_DICHIARAZIONI
(
  ID           INTEGER                          NOT NULL,
  CODICE       VARCHAR2(255 BYTE),
  DESCRIZIONE  VARCHAR2(2000 BYTE),
  CANCELLATO   INTEGER                          DEFAULT 0,
  POSIZIONE    INTEGER                          DEFAULT 0,
  OBBLIGO      INTEGER                          DEFAULT 0
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- ANAG_DICHIARAZIONI_PK  (Index) 
--
--  Dependencies: 
--   ANAG_DICHIARAZIONI (Table)
--
CREATE UNIQUE INDEX ANAG_DICHIARAZIONI_PK ON ANAG_DICHIARAZIONI
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE ANAG_DICHIARAZIONI ADD (
  CONSTRAINT ANAG_DICHIARAZIONI_PK
  PRIMARY KEY
  (ID)
  USING INDEX ANAG_DICHIARAZIONI_PK
  ENABLE VALIDATE);



--
-- BANDI  (Table) 
--
--   Row Count: 1
CREATE TABLE BANDI
(
  ID                         NUMBER             NOT NULL,
  INIZIO_PREPARAZIONE        TIMESTAMP(6),
  FINE_PREPARAZIONE          TIMESTAMP(6),
  INIZIO_CLICKDAY            TIMESTAMP(6),
  FINE_CLICKDAY              TIMESTAMP(6),
  DESCRIZIONE                VARCHAR2(255 BYTE),
  DETTAGLIO                  VARCHAR2(1000 BYTE),
  DISPONIBILITA_FINANZIARIA  NUMBER(20,4),
  COEFFICENTE_SFRATTO        NUMBER(20,4),
  COEFFICENTE                NUMBER(20,6)       DEFAULT 0
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- BANDI_PK  (Index) 
--
--  Dependencies: 
--   BANDI (Table)
--
CREATE UNIQUE INDEX BANDI_PK ON BANDI
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE BANDI ADD (
  CONSTRAINT BANDI_PK
  PRIMARY KEY
  (ID)
  USING INDEX BANDI_PK
  ENABLE VALIDATE);



--
-- COMUNE  (Table) 
--
--   Row Count: 10558
CREATE TABLE COMUNE
(
  ID                NUMBER(5)                   NOT NULL,
  CODICE_REGIONE    VARCHAR2(3 BYTE),
  CD_PROVINCIA      VARCHAR2(6 BYTE),
  CODICE_ISTAT      VARCHAR2(6 BYTE),
  DESCRIZIONE       VARCHAR2(100 BYTE),
  CODICE_PROVINCIA  VARCHAR2(5 BYTE),
  PROV              VARCHAR2(50 BYTE),
  COD_CF            VARCHAR2(10 BYTE),
  ATTIVO            NUMBER(1),
  CAP               VARCHAR2(20 BYTE),
  REGIONE           VARCHAR2(20 BYTE),
  SEARCH            INTEGER                     DEFAULT 1
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- COMUNE_PK  (Index) 
--
--  Dependencies: 
--   COMUNE (Table)
--
CREATE UNIQUE INDEX COMUNE_PK ON COMUNE
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE COMUNE ADD (
  CONSTRAINT COMUNE_PK
  PRIMARY KEY
  (ID)
  USING INDEX COMUNE_PK
  ENABLE VALIDATE);



--
-- DOCUMENTI_BANDO  (Table) 
--
--   Row Count: 2
CREATE TABLE DOCUMENTI_BANDO
(
  ID                    NUMBER                  NOT NULL,
  NOME                  VARCHAR2(500 BYTE),
  OBBLIGO               NUMBER                  DEFAULT 0,
  PRIORITA              NUMBER                  DEFAULT 0,
  FASE                  NUMBER                  DEFAULT 0,
  CANCELLATO            NUMBER                  DEFAULT 0,
  TIPO_FIRMATARIO       INTEGER                 DEFAULT 0,
  ESTENZIONE_FILE       VARCHAR2(255 BYTE),
  VERIFICA_FIRMA_P7M    INTEGER                 DEFAULT 0,
  FILE_DA_GENERARE      INTEGER                 DEFAULT 0,
  MODULE                VARCHAR2(255 BYTE),
  OBBLIGO_CONDIZIONATO  VARCHAR2(255 BYTE)
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

COMMENT ON COLUMN DOCUMENTI_BANDO.TIPO_FIRMATARIO IS '(1 = Legale Rappresentante; 2 = RUP di progetto)';

COMMENT ON COLUMN DOCUMENTI_BANDO.FILE_DA_GENERARE IS 'Se impostato a 1 il file deve essere prima generato';

COMMENT ON COLUMN DOCUMENTI_BANDO.OBBLIGO_CONDIZIONATO IS 'TABELLA|CAMPO|VALORE';


--
-- DOCUMENTI_BANDO_PK  (Index) 
--
--  Dependencies: 
--   DOCUMENTI_BANDO (Table)
--
CREATE UNIQUE INDEX DOCUMENTI_BANDO_PK ON DOCUMENTI_BANDO
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE DOCUMENTI_BANDO ADD (
  CONSTRAINT DOCUMENTI_BANDO_PK
  PRIMARY KEY
  (ID)
  USING INDEX DOCUMENTI_BANDO_PK
  ENABLE VALIDATE);



--
-- DOMANDA  (Table) 
--
--   Row Count: 3751
CREATE TABLE DOMANDA
(
  ID                  INTEGER                   NOT NULL,
  DATA_REGISTRAZIONE  TIMESTAMP(6)              DEFAULT SYSTIMESTAMP          NOT NULL,
  IBAN                VARCHAR2(50 BYTE),
  ISTITUTO_CREDITO    VARCHAR2(100 BYTE),
  FILIALE_CREDITO     VARCHAR2(100 BYTE),
  ID_ACCOUNT          NUMBER                    NOT NULL,
  DATA_RILASCIO_ISEE  DATE,
  ISEE                INTEGER                   DEFAULT 0                     NOT NULL,
  STATO               INTEGER                   DEFAULT 0                     NOT NULL,
  NOTE                VARCHAR2(3000 BYTE)
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- DOMANDA_PK  (Index) 
--
--  Dependencies: 
--   DOMANDA (Table)
--
CREATE UNIQUE INDEX DOMANDA_PK ON DOMANDA
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );
--
-- IX_ACCOUNT  (Index) 
--
--  Dependencies: 
--   DOMANDA (Table)
--
CREATE UNIQUE INDEX IX_ACCOUNT ON DOMANDA
(ID_ACCOUNT)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE DOMANDA ADD (
  CONSTRAINT DOMANDA_PK
  PRIMARY KEY
  (ID)
  USING INDEX DOMANDA_PK
  ENABLE VALIDATE);



--
-- DOMANDA_DICHIARAZIONI  (Table) 
--
--   Row Count: 0
CREATE TABLE DOMANDA_DICHIARAZIONI
(
  ID_DOMANDA             INTEGER,
  ID_ANAG_DICHIARAZIONI  INTEGER
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- DOMANDA_DICHIARAZIONI_PK  (Index) 
--
--  Dependencies: 
--   DOMANDA_DICHIARAZIONI (Table)
--
CREATE UNIQUE INDEX DOMANDA_DICHIARAZIONI_PK ON DOMANDA_DICHIARAZIONI
(ID_DOMANDA, ID_ANAG_DICHIARAZIONI)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE DOMANDA_DICHIARAZIONI ADD (
  CONSTRAINT DOMANDA_DICHIARAZIONI_PK
  PRIMARY KEY
  (ID_DOMANDA, ID_ANAG_DICHIARAZIONI)
  USING INDEX DOMANDA_DICHIARAZIONI_PK
  ENABLE VALIDATE);



--
-- DOMANDA_EMAIL  (Table) 
--
--  Dependencies: 
--   DOMANDA (Table)
--
--   Row Count: 0
CREATE TABLE DOMANDA_EMAIL
(
  ID          INTEGER                           NOT NULL,
  ID_DOMANDA  INTEGER                           NOT NULL,
  EMAIL       VARCHAR2(255 BYTE)                NOT NULL,
  ESITO       VARCHAR2(255 BYTE),
  DATA_INVIO  TIMESTAMP(6),
  STATO       INTEGER                           DEFAULT 0                     NOT NULL
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- DOMANDA_EMAIL_PK  (Index) 
--
--  Dependencies: 
--   DOMANDA_EMAIL (Table)
--
CREATE UNIQUE INDEX DOMANDA_EMAIL_PK ON DOMANDA_EMAIL
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE DOMANDA_EMAIL ADD (
  CONSTRAINT DOMANDA_EMAIL_PK
  PRIMARY KEY
  (ID)
  USING INDEX DOMANDA_EMAIL_PK
  ENABLE VALIDATE);



--
-- DOMANDA_SCONTI  (Table) 
--
--   Row Count: 3775
CREATE TABLE DOMANDA_SCONTI
(
  ID                             INTEGER        NOT NULL,
  ID_DOMANDA                     NUMBER         NOT NULL,
  COGNOME                        VARCHAR2(255 BYTE) NOT NULL,
  NOME                           VARCHAR2(255 BYTE) NOT NULL,
  DATA_NASCITA                   DATE           NOT NULL,
  RAPPORTO_PARENTELA             INTEGER        NOT NULL,
  CODICE_FISCALE                 VARCHAR2(255 BYTE) NOT NULL,
  COMUNE_RESIDENZA               VARCHAR2(255 BYTE),
  PROV_RESIDENZA                 VARCHAR2(2 BYTE),
  CAP_RESIDENZA                  VARCHAR2(5 BYTE),
  STUDENTE                       INTEGER        DEFAULT 0,
  DISABILE                       INTEGER        DEFAULT 0,
  COMPAGNIA_AEREA                VARCHAR2(255 BYTE),
  NUMERO_VOLO                    VARCHAR2(255 BYTE) NOT NULL,
  DATA_VOLO                      DATE           NOT NULL,
  COSTO_TRATTA                   FLOAT(126)     NOT NULL,
  AEROPORTO_PARTENZA             VARCHAR2(255 BYTE) NOT NULL,
  AEROPORTO_DESTINAZIONE         VARCHAR2(255 BYTE) NOT NULL,
  FILEPATH_BIGLIETTO             VARCHAR2(1000 BYTE),
  FILEPATH_CARTAIMBARCO          VARCHAR2(1000 BYTE),
  ISEE                           INTEGER        DEFAULT 0                     NOT NULL,
  DATA_RILASCIO_ISEE             DATE,
  FILEPATH_ISEE                  VARCHAR2(1000 BYTE),
  IBAN                           VARCHAR2(50 BYTE),
  ISTITUTO_CREDITO               VARCHAR2(100 BYTE),
  FILIALE_CREDITO                VARCHAR2(100 BYTE),
  STATO                          NUMBER         DEFAULT 0                     NOT NULL,
  DATA_REGISTRAZIONE             TIMESTAMP(6)   DEFAULT SYSTIMESTAMP          NOT NULL,
  ID_UID_FIREBASE                INTEGER,
  DATA_ESPORTAZIONE              TIMESTAMP(6),
  DATA_ESITO                     TIMESTAMP(6),
  DATA_EROGAZIONE                TIMESTAMP(6),
  NOTE                           VARCHAR2(3000 BYTE),
  AEROPORTO_PARTENZA_CODICE      VARCHAR2(3 BYTE),
  AEROPORTO_DESTINAZIONE_CODICE  VARCHAR2(3 BYTE),
  COMPAGNIA_ID                   INTEGER,
  DATA_ACQUISTO                  DATE,
  LOTTO                          INTEGER        DEFAULT 0                     NOT NULL,
  SCONTO_TOTALE                  NUMBER(10,4),
  FLAG                           VARCHAR2(1000 BYTE),
  PRIORITY                       INTEGER        DEFAULT 0
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

COMMENT ON COLUMN DOMANDA_SCONTI.DATA_ACQUISTO IS 'Data di acquisto del biglietto aereo';


--
-- DOMANDA_SCONTI_PK  (Index) 
--
--  Dependencies: 
--   DOMANDA_SCONTI (Table)
--
CREATE UNIQUE INDEX DOMANDA_SCONTI_PK ON DOMANDA_SCONTI
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );
--
-- KY_SCONTI_IX  (Index) 
--
--  Dependencies: 
--   DOMANDA_SCONTI (Table)
--
CREATE UNIQUE INDEX KY_SCONTI_IX ON DOMANDA_SCONTI
(CODICE_FISCALE, NUMERO_VOLO, DATA_VOLO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE DOMANDA_SCONTI ADD (
  CONSTRAINT DOMANDA_SCONTI_PK
  PRIMARY KEY
  (ID)
  USING INDEX DOMANDA_SCONTI_PK
  ENABLE VALIDATE);



--
-- ESPORTAZIONI  (Table) 
--
--   Row Count: 12
CREATE TABLE ESPORTAZIONI
(
  LOTTO           INTEGER                       NOT NULL,
  DATA_CREAZIONE  TIMESTAMP(6)                  DEFAULT SYSTIMESTAMP
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- ESPORTAZIONI_PK  (Index) 
--
--  Dependencies: 
--   ESPORTAZIONI (Table)
--
CREATE UNIQUE INDEX ESPORTAZIONI_PK ON ESPORTAZIONI
(LOTTO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE ESPORTAZIONI ADD (
  CONSTRAINT ESPORTAZIONI_PK
  PRIMARY KEY
  (LOTTO)
  USING INDEX ESPORTAZIONI_PK
  ENABLE VALIDATE);



--
-- FAQ  (Table) 
--
--   Row Count: 2
CREATE TABLE FAQ
(
  ID                     NUMBER                 NOT NULL,
  ID_UID_FIREBASE_ADMIN  NUMBER,
  OGGETTO                VARCHAR2(1000 BYTE),
  PUBBLICATA             NUMBER                 DEFAULT 0                     NOT NULL,
  CANCELLATO             NUMBER                 DEFAULT 0                     NOT NULL,
  DATA_INSERIMENTO       TIMESTAMP(6)           DEFAULT SYSTIMESTAMP,
  ID_CATEGORIA           NUMBER,
  BANDO                  NUMBER                 DEFAULT 0,
  DOMANDA                VARCHAR2(1000 BYTE)
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- FAQ_PK  (Index) 
--
--  Dependencies: 
--   FAQ (Table)
--
CREATE UNIQUE INDEX FAQ_PK ON FAQ
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE FAQ ADD (
  CONSTRAINT FAQ_PK
  PRIMARY KEY
  (ID)
  USING INDEX FAQ_PK
  ENABLE VALIDATE);



--
-- FAQ_UTENTI  (Table) 
--
--   Row Count: 0
CREATE TABLE FAQ_UTENTI
(
  ID                NUMBER                      NOT NULL,
  NOME              VARCHAR2(200 BYTE),
  COGNOME           VARCHAR2(200 BYTE),
  EMAIL             VARCHAR2(100 BYTE),
  STATO             NUMBER                      DEFAULT 0                     NOT NULL,
  DOMANDA           VARCHAR2(1000 BYTE),
  ID_CATEGORIA      NUMBER,
  BANDO             NUMBER                      DEFAULT 0,
  DATA_INSERIMENTO  TIMESTAMP(6)                DEFAULT SYSTIMESTAMP,
  ACCOUNT           VARCHAR2(20 BYTE)
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- FAQ_UTENTI_PK  (Index) 
--
--  Dependencies: 
--   FAQ_UTENTI (Table)
--
CREATE UNIQUE INDEX FAQ_UTENTI_PK ON FAQ_UTENTI
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE FAQ_UTENTI ADD (
  CONSTRAINT FAQ_UTENTI_PK
  PRIMARY KEY
  (ID)
  USING INDEX FAQ_UTENTI_PK
  ENABLE VALIDATE);



--
-- LOGS  (Table) 
--
--   Row Count: 22717
CREATE TABLE LOGS
(
  ID            NUMBER(38)                      NOT NULL,
  ID_OPERATORE  VARCHAR2(255 BYTE),
  IP            VARCHAR2(255 BYTE),
  USERNAME      VARCHAR2(255 BYTE),
  DATA          TIMESTAMP(6)                    DEFAULT SYSTIMESTAMP          NOT NULL,
  MODULE        VARCHAR2(255 BYTE),
  ACTION        VARCHAR2(255 BYTE),
  INFO          CLOB,
  OLDVALUE      CLOB,
  OPERATION     CLOB
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- LOGS_PK  (Index) 
--
--  Dependencies: 
--   LOGS (Table)
--
CREATE UNIQUE INDEX LOGS_PK ON LOGS
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- LOGS_BE  (Table) 
--
--   Row Count: 38
CREATE TABLE LOGS_BE
(
  ID            NUMBER(38)                      NOT NULL,
  ID_OPERATORE  VARCHAR2(255 BYTE),
  IP            VARCHAR2(255 BYTE),
  USERNAME      VARCHAR2(255 BYTE),
  DATA          TIMESTAMP(6)                    DEFAULT SYSTIMESTAMP          NOT NULL,
  MODULE        VARCHAR2(255 BYTE),
  ACTION        VARCHAR2(255 BYTE),
  INFO          CLOB,
  OLDVALUE      CLOB,
  OPERATION     CLOB
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- LOGS_BE_PK  (Index) 
--
--  Dependencies: 
--   LOGS_BE (Table)
--
CREATE UNIQUE INDEX LOGS_BE_PK ON LOGS_BE
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- LOGS_P7M  (Table) 
--
--   Row Count: 0
CREATE TABLE LOGS_P7M
(
  ID          INTEGER,
  ID_DOMANDA  INTEGER,
  ERRORE      VARCHAR2(4000 BYTE),
  FILEPATH    VARCHAR2(4000 BYTE),
  DATA        TIMESTAMP(6)                      DEFAULT SYSTIMESTAMP,
  FASE        NUMBER
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- LOGS_P7M_PK  (Index) 
--
--  Dependencies: 
--   LOGS_P7M (Table)
--
CREATE UNIQUE INDEX LOGS_P7M_PK ON LOGS_P7M
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- SPID_ACCESSI  (Table) 
--
--   Row Count: 0
CREATE TABLE SPID_ACCESSI
(
  ID              NUMBER                        NOT NULL,
  CODICE_FISCALE  VARCHAR2(30 BYTE),
  INRESPONSETO    VARCHAR2(200 BYTE),
  AUTHNINSTANT    VARCHAR2(200 BYTE),
  DATA            TIMESTAMP(6)                  DEFAULT SYSTIMESTAMP
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- SPID_ACCESSI_PK  (Index) 
--
--  Dependencies: 
--   SPID_ACCESSI (Table)
--
CREATE UNIQUE INDEX SPID_ACCESSI_PK ON SPID_ACCESSI
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- UID_FIREBASE_ADMIN  (Table) 
--
--   Row Count: 2
CREATE TABLE UID_FIREBASE_ADMIN
(
  ID          NUMBER                            NOT NULL,
  GUID        VARCHAR2(1000 BYTE),
  EMAIL       VARCHAR2(255 BYTE),
  NOME        VARCHAR2(255 BYTE),
  COGNOME     VARCHAR2(255 BYTE),
  SUPER_USER  INTEGER                           NOT NULL,
  GROUP_ID    INTEGER                           DEFAULT 0,
  VERIFICATO  INTEGER                           DEFAULT 0
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- UID_FIREBASE_ADMIN_PK  (Index) 
--
--  Dependencies: 
--   UID_FIREBASE_ADMIN (Table)
--
CREATE UNIQUE INDEX UID_FIREBASE_ADMIN_PK ON UID_FIREBASE_ADMIN
(ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE UID_FIREBASE_ADMIN ADD (
  CONSTRAINT UID_FIREBASE_ADMIN_PK
  PRIMARY KEY
  (ID)
  USING INDEX UID_FIREBASE_ADMIN_PK
  ENABLE VALIDATE);



--
-- FAQ_INDEX1  (Index) 
--
--  Dependencies: 
--   FAQ (Table)
--
CREATE INDEX FAQ_INDEX1 ON FAQ
(ID_UID_FIREBASE_ADMIN)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- FAQ_INDEX2  (Index) 
--
--  Dependencies: 
--   FAQ (Table)
--
CREATE INDEX FAQ_INDEX2 ON FAQ
(PUBBLICATA)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- FAQ_INDEX3  (Index) 
--
--  Dependencies: 
--   FAQ (Table)
--
CREATE INDEX FAQ_INDEX3 ON FAQ
(CANCELLATO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- FAQ_INDEX4  (Index) 
--
--  Dependencies: 
--   FAQ (Table)
--
CREATE INDEX FAQ_INDEX4 ON FAQ
(ID_CATEGORIA)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_ACC_ANAG_CF  (Index) 
--
--  Dependencies: 
--   ACCOUNT_ANAGRAFICA (Table)
--
CREATE INDEX IX_ACC_ANAG_CF ON ACCOUNT_ANAGRAFICA
(CODICE_FISCALE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_ACC_ANAG_DATA_REC  (Index) 
--
--  Dependencies: 
--   ACCOUNT_ANAGRAFICA (Table)
--
CREATE INDEX IX_ACC_ANAG_DATA_REC ON ACCOUNT_ANAGRAFICA
(DATA_REGISTRAZIONE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_ALLEGATI_DOCUMENTO  (Index) 
--
--  Dependencies: 
--   ALLEGATI (Table)
--
CREATE INDEX IX_ALLEGATI_DOCUMENTO ON ALLEGATI
(ID_DOCUMENTO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_ALLEGATI_DOMANDA  (Index) 
--
--  Dependencies: 
--   ALLEGATI (Table)
--
CREATE INDEX IX_ALLEGATI_DOMANDA ON ALLEGATI
(ID_DOMANDA)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_ALLEGATI_TIPODOCUMENTO  (Index) 
--
--  Dependencies: 
--   ALLEGATI (Table)
--
CREATE INDEX IX_ALLEGATI_TIPODOCUMENTO ON ALLEGATI
(TIPO_DOCUMENTO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_AUTORIZZAZIONE  (Index) 
--
--  Dependencies: 
--   ACCOUNT (Table)
--
CREATE INDEX IX_AUTORIZZAZIONE ON ACCOUNT
(AUTORIZZAZIONE_TRATTAMENTO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_BANDI_FC  (Index) 
--
--  Dependencies: 
--   BANDI (Table)
--
CREATE INDEX IX_BANDI_FC ON BANDI
(FINE_CLICKDAY)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_BANDI_FP  (Index) 
--
--  Dependencies: 
--   BANDI (Table)
--
CREATE INDEX IX_BANDI_FP ON BANDI
(FINE_PREPARAZIONE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_BANDI_IC  (Index) 
--
--  Dependencies: 
--   BANDI (Table)
--
CREATE INDEX IX_BANDI_IC ON BANDI
(INIZIO_CLICKDAY)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_BANDI_IP  (Index) 
--
--  Dependencies: 
--   BANDI (Table)
--
CREATE INDEX IX_BANDI_IP ON BANDI
(INIZIO_PREPARAZIONE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_COMUNE_ATTIVO  (Index) 
--
--  Dependencies: 
--   COMUNE (Table)
--
CREATE INDEX IX_COMUNE_ATTIVO ON COMUNE
(ATTIVO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_COMUNE_CODICE_PROV  (Index) 
--
--  Dependencies: 
--   COMUNE (Table)
--
CREATE INDEX IX_COMUNE_CODICE_PROV ON COMUNE
(CODICE_PROVINCIA)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_COMUNE_DESCRIZIONE  (Index) 
--
--  Dependencies: 
--   COMUNE (Table)
--
CREATE INDEX IX_COMUNE_DESCRIZIONE ON COMUNE
(DESCRIZIONE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_COMUNE_ISTAT  (Index) 
--
--  Dependencies: 
--   COMUNE (Table)
--
CREATE INDEX IX_COMUNE_ISTAT ON COMUNE
(CODICE_ISTAT)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_COMUNE_REGIONE  (Index) 
--
--  Dependencies: 
--   COMUNE (Table)
--
CREATE INDEX IX_COMUNE_REGIONE ON COMUNE
(REGIONE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_DOCUMENTI_BANDO_FASE  (Index) 
--
--  Dependencies: 
--   DOCUMENTI_BANDO (Table)
--
CREATE INDEX IX_DOCUMENTI_BANDO_FASE ON DOCUMENTI_BANDO
(FASE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_DOCUMENTI_BANDO_OBBLIGO  (Index) 
--
--  Dependencies: 
--   DOCUMENTI_BANDO (Table)
--
CREATE INDEX IX_DOCUMENTI_BANDO_OBBLIGO ON DOCUMENTI_BANDO
(OBBLIGO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_DOCUMENTI_BANDO_PRIORITA  (Index) 
--
--  Dependencies: 
--   DOCUMENTI_BANDO (Table)
--
CREATE INDEX IX_DOCUMENTI_BANDO_PRIORITA ON DOCUMENTI_BANDO
(PRIORITA)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_FAQ_UT_ACC  (Index) 
--
--  Dependencies: 
--   FAQ_UTENTI (Table)
--
CREATE INDEX IX_FAQ_UT_ACC ON FAQ_UTENTI
(ACCOUNT)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_FAQ_UT_CAT  (Index) 
--
--  Dependencies: 
--   FAQ_UTENTI (Table)
--
CREATE INDEX IX_FAQ_UT_CAT ON FAQ_UTENTI
(ID_CATEGORIA)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_FAQ_UT_DATAI  (Index) 
--
--  Dependencies: 
--   FAQ_UTENTI (Table)
--
CREATE INDEX IX_FAQ_UT_DATAI ON FAQ_UTENTI
(DATA_INSERIMENTO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_FIREBASE_ADMIN_EMAIL  (Index) 
--
--  Dependencies: 
--   UID_FIREBASE_ADMIN (Table)
--
CREATE INDEX IX_FIREBASE_ADMIN_EMAIL ON UID_FIREBASE_ADMIN
(EMAIL)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_FIREBASE_ADMIN_GROUP  (Index) 
--
--  Dependencies: 
--   UID_FIREBASE_ADMIN (Table)
--
CREATE INDEX IX_FIREBASE_ADMIN_GROUP ON UID_FIREBASE_ADMIN
(GROUP_ID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_FIREBASE_ADMIN_GUID  (Index) 
--
--  Dependencies: 
--   UID_FIREBASE_ADMIN (Table)
--
CREATE INDEX IX_FIREBASE_ADMIN_GUID ON UID_FIREBASE_ADMIN
(GUID)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_FIREBASE_ADMIN_SU  (Index) 
--
--  Dependencies: 
--   UID_FIREBASE_ADMIN (Table)
--
CREATE INDEX IX_FIREBASE_ADMIN_SU ON UID_FIREBASE_ADMIN
(SUPER_USER)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_OBBLIGO  (Index) 
--
--  Dependencies: 
--   ANAG_DICHIARAZIONI (Table)
--
CREATE INDEX IX_OBBLIGO ON ANAG_DICHIARAZIONI
(OBBLIGO)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_POSIZIONE  (Index) 
--
--  Dependencies: 
--   ANAG_DICHIARAZIONI (Table)
--
CREATE INDEX IX_POSIZIONE ON ANAG_DICHIARAZIONI
(POSIZIONE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_SA_CF  (Index) 
--
--  Dependencies: 
--   SPID_ACCESSI (Table)
--
CREATE INDEX IX_SA_CF ON SPID_ACCESSI
(CODICE_FISCALE)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_SA_DATA  (Index) 
--
--  Dependencies: 
--   SPID_ACCESSI (Table)
--
CREATE INDEX IX_SA_DATA ON SPID_ACCESSI
(DATA)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_SEARCH  (Index) 
--
--  Dependencies: 
--   COMUNE (Table)
--
CREATE INDEX IX_SEARCH ON COMUNE
(SEARCH)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- IX_USER_ACCOUNT  (Index) 
--
--  Dependencies: 
--   ACCOUNT (Table)
--
CREATE INDEX IX_USER_ACCOUNT ON ACCOUNT
(USERNAME)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

--
-- SPAEROPORTISAVE  (Procedure) 
--
--  Dependencies: 
--   AEROPORTI (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SPAEROPORTISAVE" 
(
    P_CODICE  VARCHAR2,
    P_NOME  VARCHAR2,
    P_REGIONE NUMBER 
) AS 
INSUPDATE  NUMBER;
BEGIN

SELECT COUNT(*) INTO INSUPDATE  FROM AEROPORTI WHERE CODICE = P_CODICE;

IF INSUPDATE <= 0 THEN
        INSERT INTO AEROPORTI (CODICE, NOME, REGIONE) VALUES (P_CODICE, P_NOME, P_REGIONE);
ELSE
        UPDATE AEROPORTI SET NOME = P_NOME, REGIONE = P_REGIONE WHERE CODICE = P_CODICE;
END IF;

END SPAEROPORTISAVE;
/


--
-- SP_APPROVA  (Procedure) 
--
--  Dependencies: 
--   DOMANDA_SCONTI (Table)
--   ESPORTAZIONI (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SP_APPROVA" 
(
  P_NUM_LOTTO INT
) AS 
    CTR_LOTTO INT;
BEGIN
CTR_LOTTO:=0;

SELECT LOTTO INTO CTR_LOTTO FROM ESPORTAZIONI WHERE LOTTO = P_NUM_LOTTO;


IF CTR_LOTTO > 0 THEN
    
    UPDATE DOMANDA_SCONTI SET
        STATO = 2,    
        DATA_ESITO = SYSTIMESTAMP  
    WHERE LOTTO = P_NUM_LOTTO AND STATO = 1; 
END IF;


END SP_APPROVA;
/


--
-- SPDICHIARAZIONISAVE  (Procedure) 
--
--  Dependencies: 
--   DOMANDA_DICHIARAZIONI (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SPDICHIARAZIONISAVE" 
(
  P_ID_DOMANDA  INT 
, P_ID_ANAG_DICHIARAZIONI INT
) AS 

BEGIN

INSERT INTO DOMANDA_DICHIARAZIONI (ID_DOMANDA, ID_ANAG_DICHIARAZIONI ) VALUES (P_ID_DOMANDA, P_ID_ANAG_DICHIARAZIONI);

END SPDICHIARAZIONISAVE;
/


--
-- SP_DISAPPROVA  (Procedure) 
--
--  Dependencies: 
--   DOMANDA_SCONTI (Table)
--   ESPORTAZIONI (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SP_DISAPPROVA" 
(
  P_NUM_LOTTO INT
) AS 
    CTR_LOTTO INT;
BEGIN
CTR_LOTTO:=0;

SELECT LOTTO INTO CTR_LOTTO FROM ESPORTAZIONI WHERE LOTTO = P_NUM_LOTTO;


IF CTR_LOTTO > 0 THEN
    
    UPDATE DOMANDA_SCONTI SET
        STATO = 1,    
        DATA_ESITO = null, 
        DATA_ESPORTAZIONE = SYSTIMESTAMP
    WHERE LOTTO = P_NUM_LOTTO AND STATO = 2; 
END IF;


END SP_DISAPPROVA;
/


--
-- SP_EROGA  (Procedure) 
--
--  Dependencies: 
--   DOMANDA_SCONTI (Table)
--   ESPORTAZIONI (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SP_EROGA" 
(
  P_NUM_LOTTO INT
) AS 
    CTR_LOTTO INT;
BEGIN
CTR_LOTTO:=0;

SELECT LOTTO INTO CTR_LOTTO FROM ESPORTAZIONI WHERE LOTTO = P_NUM_LOTTO;


IF CTR_LOTTO > 0 THEN
    
    UPDATE DOMANDA_SCONTI SET
        STATO = 3,    
        DATA_EROGAZIONE = SYSTIMESTAMP  
    WHERE LOTTO = P_NUM_LOTTO AND STATO = 2; 
END IF;


END SP_EROGA;
/


--
-- SPLOGSBESAVE  (Procedure) 
--
--  Dependencies: 
--   LOGS_BE (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SPLOGSBESAVE" 
(
  P_ID_OPERATORE IN VARCHAR2 
, P_IP IN VARCHAR2 
, P_USERNAME IN VARCHAR2 
, P_MODULE IN VARCHAR2 
, P_ACTION IN VARCHAR2 
, P_OPERATION IN VARCHAR2 
, P_INFO IN CLOB 
, P_OLDVALUE IN CLOB 
) AS 
BEGIN
  INSERT INTO LOGS_BE
    (ID_OPERATORE, IP, USERNAME, DATA, MODULE, ACTION, OPERATION, INFO, OLDVALUE)
  	VALUES
    (P_ID_OPERATORE, P_IP, P_USERNAME, SYSTIMESTAMP, P_MODULE, P_ACTION, P_OPERATION, P_INFO, P_OLDVALUE);
END SPLOGSBESAVE;
/


--
-- SPLOGSP7MSAVE  (Procedure) 
--
--  Dependencies: 
--   LOGS_P7M (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SPLOGSP7MSAVE" 
(
  P_ID_DOMANDA IN NUMBER
, P_ERRORE IN VARCHAR2 
, P_FILEPATH IN VARCHAR2 
, P_FASE IN NUMBER
) AS 
BEGIN
  INSERT INTO LOGS_P7M
    (ID_DOMANDA, ERRORE, FILEPATH, DATA, FASE)
  	VALUES
    (P_ID_DOMANDA, P_ERRORE, P_FILEPATH, SYSTIMESTAMP, P_FASE);
END SPLOGSP7MSAVE;
/


--
-- SPLOGSSAVE  (Procedure) 
--
--  Dependencies: 
--   LOGS (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SPLOGSSAVE" 
(
  P_ID_OPERATORE IN VARCHAR2 
, P_IP IN VARCHAR2 
, P_USERNAME IN VARCHAR2 
, P_MODULE IN VARCHAR2 
, P_ACTION IN VARCHAR2 
, P_OPERATION IN VARCHAR2 
, P_INFO IN CLOB 
, P_OLDVALUE IN CLOB 
) AS 
BEGIN
  INSERT INTO LOGS
    (ID_OPERATORE, IP, USERNAME, DATA, MODULE, ACTION, OPERATION, INFO, OLDVALUE)
  	VALUES
    (P_ID_OPERATORE, P_IP, P_USERNAME, SYSTIMESTAMP, P_MODULE, P_ACTION, P_OPERATION, P_INFO, P_OLDVALUE);
END SPLOGSSAVE;
/


--
-- CALCOLAFRAZIONEANNO  (Function) 
--
--  Dependencies: 
--   DUAL (Synonym)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE FUNCTION "CALCOLAFRAZIONEANNO" (
P_DATA_INIZIO IN DATE, 
P_DATA_FINE IN DATE
) RETURN NUMBER IS
ANNI NUMBER;
MESI NUMBER;
GIORNI NUMBER;
PLUS NUMBER;
--DATA_INIZIO DATE;
DATA_FINE DATE;

BEGIN
   ANNI := 0;
   MESI := 0;
   PLUS := 0;
   --DATA_INIZIO := TO_DATE('01/01/2000 00:00:00','dd/mm/YYYY hh24:mi:ss');
   DATA_FINE := P_DATA_FINE+1; -- AGGIUNGO IL GIORNO ESTREMO DEL PERIODO

   /*SELECT 
    TRUNC (MONTHS_BETWEEN (P_DATA_FINE, P_DATA_INIZIO) / 12),
    MOD (TRUNC (MONTHS_BETWEEN (P_DATA_FINE, P_DATA_INIZIO)), 12),
    (P_DATA_FINE - ADD_MONTHS (P_DATA_INIZIO, TRUNC(MONTHS_BETWEEN (P_DATA_FINE,P_DATA_INIZIO))))
    INTO ANNI, MESI, GIORNI FROM DUAL;*/

    WITH T (START_DATE, END_DATE) AS (
      SELECT P_DATA_INIZIO, DATA_FINE FROM DUAL
    )
    SELECT
      TRUNC(MONTH_DIFF/12),
      TRUNC(MOD(MONTH_DIFF, 12)),
    (END_DATE - ADD_MONTHS(START_DATE, MONTH_DIFF)) INTO ANNI, MESI, GIORNI
    FROM (
      SELECT START_DATE, END_DATE,
        TRUNC(MONTHS_BETWEEN(END_DATE, START_DATE)) AS MONTH_DIFF
      FROM T
    );

   --GIORNI := GIORNI+1;

   IF GIORNI = 30 THEN
    MESI := MESI+1;
    IF MESI = 12 THEN
        MESI := 0;
        ANNI := ANNI+1;    
    END IF;    
   END IF;


   IF MESI >= 6 THEN
   PLUS := 1;
   ELSE
   PLUS := 0;
   END IF;
   RETURN (ANNI+PLUS);

END CALCOLAFRAZIONEANNO;
/


--
-- CONTROLLOPERIODO  (Function) 
--
--  Dependencies: 
--   BANDI (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE FUNCTION "CONTROLLOPERIODO" (
P_PERIODO IN VARCHAR2,
P_ID_BANDO IN NUMBER
)
RETURN number IS
    PERIODO_OK number;   
BEGIN 
    IF (P_PERIODO = 'PREPARAZIONE' AND P_ID_BANDO > 0) THEN

        SELECT count(ID) INTO PERIODO_OK FROM BANDI where ID = P_ID_BANDO AND SYSTIMESTAMP BETWEEN  INIZIO_PREPARAZIONE AND FINE_PREPARAZIONE;

    ELSIF (P_PERIODO = 'CLICKDAY' AND P_ID_BANDO > 0) THEN

        SELECT count(ID) INTO PERIODO_OK FROM BANDI where ID = P_ID_BANDO AND SYSTIMESTAMP BETWEEN  INIZIO_CLICKDAY AND FINE_CLICKDAY;

    END IF;

    RETURN PERIODO_OK;
END;
/


--
-- F_DECRYPT  (Function) 
--
--  Dependencies: 
--   ALGPARAMETERS (Table)
--   DBMS_CRYPTO (Synonym)
--   UTL_ENCODE (Synonym)
--   UTL_I18N (Synonym)
--   UTL_RAW (Synonym)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE FUNCTION F_DECRYPT (p_input VARCHAR2)
   RETURN VARCHAR2
AS
   v_decrypted_raw     RAW (2000);
   v_key               RAW (320);
   v_encryption_type   PLS_INTEGER := DBMS_CRYPTO.DES_CBC_PKCS5;
   v_iv                RAW (320);
BEGIN
   SELECT VALUE
     INTO v_key
     FROM algparameters
    WHERE name = 'key';

   SELECT VALUE
     INTO v_iv
     FROM algparameters
    WHERE name = 'iv';


   v_decrypted_raw :=
      DBMS_CRYPTO.DECRYPT (
         src   => UTL_ENCODE.base64_decode (UTL_RAW.CAST_TO_RAW (p_input)),
         typ   => v_encryption_type,
         key   => v_key,
         iv    => v_iv);


   RETURN UTL_I18N.RAW_TO_CHAR (v_decrypted_raw, 'AL32UTF8');
END;
/


--
-- F_ENCRYPT  (Function) 
--
--  Dependencies: 
--   ALGPARAMETERS (Table)
--   DBMS_CRYPTO (Synonym)
--   UTL_ENCODE (Synonym)
--   UTL_I18N (Synonym)
--   UTL_RAW (Synonym)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE FUNCTION F_ENCRYPT (p_input VARCHAR2)
   RETURN VARCHAR2
AS
   v_encrypted_raw     RAW (2000);
   v_key               RAW (320);
   v_encryption_type   PLS_INTEGER
      :=   DBMS_CRYPTO.DES_CBC_PKCS5;
   v_iv                RAW (320);
BEGIN
   SELECT VALUE
     INTO v_key
     FROM algparameters
    WHERE name = 'key';

   SELECT VALUE
     INTO v_iv
     FROM algparameters
    WHERE name = 'iv';

   v_encrypted_raw :=
      DBMS_CRYPTO.encrypt (src   => UTL_I18N.STRING_TO_RAW (p_input, 'AL32UTF8'),
                           typ   => v_encryption_type,
                           key   => v_key,
                           iv    => v_iv);
   RETURN UTL_RAW.CAST_TO_VARCHAR2 (UTL_ENCODE.base64_encode (v_encrypted_raw));
END;
/


--
-- FNGETSCONTO  (Function) 
--
--  Dependencies: 
--   ACCOUNT_NUCLEO_FAMILIARE (Table)
--   ANAG_COMPAGNIE (Table)
--   DOMANDA (Table)
--   DOMANDA_SCONTI (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE FUNCTION "FNGETSCONTO" (    
    P_ID IN NUMBER,
    P_TIPO IN VARCHAR
) RETURN VARCHAR IS
T_ID_DOMANDA INT;
T_ISEE INT;
T_PRIORITY NUMBER;
T_BENEFICIARIO VARCHAR(255);
COSTO_VOLO NUMBER;
T_COMPAGNIA_ID INT;
CATEGORIA_PRIORITARIA NUMBER;
SCONTO_RESIDENTI NUMBER;
SCONTO_PRIORITARI NUMBER;
SCONTO_TOTALE NUMBER;
PERC_RESIDENTI NUMBER;
PERC_PRIORITARI NUMBER;
MINIMO_COSTO NUMBER;
SCONTO_MASSIMO NUMBER;
CTR_STATO INT;
CTR_ADESIONE INT;
T_DATA_VOLO DATE;
T_DATA_ADESIONE DATE;
T_DATA_ACQUISTO DATE;
T_ID_ACCOUNT INT;
RESULT VARCHAR(255);
BEGIN
    MINIMO_COSTO := 1;   
    SCONTO_MASSIMO := 75;
    PERC_RESIDENTI := 25;
    PERC_PRIORITARI := 25;
    SCONTO_PRIORITARI :=0;
    CTR_ADESIONE :=0;
       
    SELECT 
       ID_DOMANDA, STATO, CODICE_FISCALE, COSTO_TRATTA, ISEE, 
       COMPAGNIA_ID, DATA_VOLO, DATA_ACQUISTO, PRIORITY INTO T_ID_DOMANDA, CTR_STATO, T_BENEFICIARIO, 
       COSTO_VOLO, T_ISEE, T_COMPAGNIA_ID, T_DATA_VOLO, T_DATA_ACQUISTO, T_PRIORITY FROM DOMANDA_SCONTI WHERE ID = P_ID;
       -- se lo stato della richiesta di sconto è = 0 
    IF CTR_STATO = 0 THEN
        SELECT  ISEE, ID_ACCOUNT INTO T_ISEE, T_ID_ACCOUNT FROM DOMANDA WHERE ID = T_ID_DOMANDA;
        SELECT  PRIORITY INTO T_PRIORITY FROM ACCOUNT_NUCLEO_FAMILIARE WHERE CODICE_FISCALE = T_BENEFICIARIO AND ID_ACCOUNT = T_ID_ACCOUNT;   
         
    END IF;
       
    IF T_COMPAGNIA_ID > 0 THEN
       SELECT ADESIONE, DATA_ADESIONE INTO CTR_ADESIONE, T_DATA_ADESIONE FROM ANAG_COMPAGNIE WHERE ID = T_COMPAGNIA_ID;
    END IF;
       
    IF T_PRIORITY > 0 OR T_ISEE > 0 THEN
        CATEGORIA_PRIORITARIA := 1;
    ELSE 
        CATEGORIA_PRIORITARIA := 0;
    END IF;
   
   
    -- SE LA COMPAGNIA HA ADERITO ALLO SCONTO DEL 25% GIA APPLICATO AL PREZZO DEL BIGLIETTO NON CONSIDERO LO SCONTO RESIDENTI
    IF CTR_ADESIONE = 1 AND T_DATA_ADESIONE <= T_DATA_ACQUISTO THEN   
        COSTO_VOLO := (COSTO_VOLO/(1-(PERC_RESIDENTI/100)));       
        SCONTO_RESIDENTI := 0;
    ELSE
        SCONTO_RESIDENTI := (COSTO_VOLO*PERC_RESIDENTI/100);
    END IF;
   
   
    IF CATEGORIA_PRIORITARIA = 1 THEN 
        SCONTO_PRIORITARI := (COSTO_VOLO*PERC_PRIORITARI/100);
    END IF;
   
   
    SCONTO_TOTALE := SCONTO_RESIDENTI+SCONTO_PRIORITARI;
    
    IF SCONTO_TOTALE > SCONTO_MASSIMO THEN
        SCONTO_TOTALE := SCONTO_MASSIMO;
    END IF; 

    CASE WHEN P_TIPO = 'CATEGORIA_PRIORITARIA' THEN     
        -- Restituisce solo L'INCIDENZA
        RESULT := CATEGORIA_PRIORITARIA;
    WHEN P_TIPO = 'SCONTO_PRIORITARI' THEN

        RESULT := SCONTO_PRIORITARI;    
    WHEN P_TIPO = 'SCONTO_RESIDENTI' THEN
        
        RESULT := SCONTO_RESIDENTI;    
    ELSE    
        RESULT := SCONTO_TOTALE;

    END CASE;               

    RETURN RESULT;

END FNGETSCONTO;
/


--
-- GET_IDENTIFICATIVO  (Function) 
--
--  Dependencies: 
--   STANDARD (Package)
--
CREATE OR REPLACE FUNCTION "GET_IDENTIFICATIVO" (
P_ID IN NUMBER,
P_DATA_REGISTRAZIONE IN TIMESTAMP
)
RETURN VARCHAR2 IS
    IDENTIFICATIVO VARCHAR2(30);
BEGIN 
    IDENTIFICATIVO := 'D'||TO_CHAR(P_DATA_REGISTRAZIONE,'YYYYmm')||LPAD(to_char(P_ID), 6, '0' );   
    RETURN IDENTIFICATIVO;
END;
/


--
-- GETPERIODOANNIMESIGIORNI  (Function) 
--
--  Dependencies: 
--   DUAL (Synonym)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE FUNCTION "GETPERIODOANNIMESIGIORNI" (
P_DATA_INIZIO IN DATE, 
P_DATA_FINE IN DATE,
P_TIPO IN VARCHAR
) RETURN NUMBER IS
ANNI NUMBER;
MESI NUMBER;
GIORNI NUMBER;
PLUS NUMBER;
RESULT NUMBER;
DATA_FINE DATE;

BEGIN
   ANNI := 0;
   MESI := 0;
   GIORNI := 0;
   PLUS := 0;
   RESULT := 0;
   --DATA_INIZIO := TO_DATE('01/01/2000 00:00:00','dd/mm/YYYY hh24:mi:ss');
   DATA_FINE := P_DATA_FINE; -- AGGIUNGO IL GIORNO ESTREMO DEL PERIODO

   /*SELECT 
    TRUNC (MONTHS_BETWEEN (P_DATA_FINE, P_DATA_INIZIO) / 12),
    MOD (TRUNC (MONTHS_BETWEEN (P_DATA_FINE, P_DATA_INIZIO)), 12),
    (P_DATA_FINE - ADD_MONTHS (P_DATA_INIZIO, TRUNC(MONTHS_BETWEEN (P_DATA_FINE,P_DATA_INIZIO))))
    INTO ANNI, MESI, GIORNI FROM DUAL;
   */
    WITH T (START_DATE, END_DATE) AS (
      SELECT P_DATA_INIZIO, DATA_FINE FROM DUAL
    )
    SELECT
      TRUNC(MONTH_DIFF/12),
      TRUNC(MOD(MONTH_DIFF, 12)),
      TRUNC(END_DATE - ADD_MONTHS(START_DATE, MONTH_DIFF)) INTO ANNI, MESI, GIORNI
    FROM (
      SELECT START_DATE, END_DATE,
        TRUNC(MONTHS_BETWEEN(END_DATE, START_DATE)) AS MONTH_DIFF
      FROM T
    );
    --GIORNI := GIORNI+1;

   IF GIORNI = 30 THEN
        GIORNI := 0;
        MESI := (MESI + 1);
        IF MESI = 12 THEN
            MESI := 0;
            ANNI := (ANNI + 1);
        END IF;

   END IF;



   CASE WHEN P_TIPO = 'ANNI' THEN     
        -- Restituisce solo il numero di anni
        RESULT := ANNI;
    WHEN P_TIPO = 'MESI' THEN
        -- Restituisce solo il numero di mesi
        RESULT := MESI;
    WHEN P_TIPO = 'GIORNI' THEN
        -- Restituisce solo il numero di giorni
        RESULT := GIORNI;    
   ELSE    
        -- Restituisce solo il numero di anni frazionati sommando 
        IF MESI >= 6 THEN
            PLUS := 1;
        ELSE
           PLUS := 0;
        END IF;
        RESULT := (ANNI+PLUS);

    END CASE;               

   RETURN RESULT ;

END GETPERIODOANNIMESIGIORNI;
/


--
-- VIEW_EXPORT_SCONTI  (View) 
--
--  Dependencies: 
--   ACCOUNT_NUCLEO_FAMILIARE (Table)
--   DOMANDA (Table)
--   DOMANDA_SCONTI (Table)
--   FNGETSCONTO (Function)
--
CREATE OR REPLACE FORCE VIEW VIEW_EXPORT_SCONTI
(ID, ID_DOMANDA, COGNOME, NOME, DATA_NASCITA, 
 RAPPORTO_PARENTELA, CODICE_FISCALE, COMUNE_RESIDENZA, PROV_RESIDENZA, CAP_RESIDENZA, 
 COMPAGNIA_AEREA, NUMERO_VOLO, DATA_VOLO, COSTO_TRATTA, AEROPORTO_PARTENZA, 
 AEROPORTO_PARTENZA_CODICE, AEROPORTO_DESTINAZIONE, AEROPORTO_DESTINAZIONE_CODICE, FILEPATH_BIGLIETTO, FILEPATH_CARTAIMBARCO, 
 ISEE, DATA_RILASCIO_ISEE, IBAN, ISTITUTO_CREDITO, FILIALE_CREDITO, 
 STATO, DATA_REGISTRAZIONE, ID_UID_FIREBASE, DATA_ESPORTAZIONE, DATA_ESITO, 
 DATA_EROGAZIONE, NOTE, SCONTO_TOTALE, COMPAGNIA_ID, DATA_ACQUISTO, 
 LOTTO, FLAG, PRIORITA)
BEQUEATH DEFINER
AS 
SELECT DS.ID,
           DS.ID_DOMANDA,
           DS.COGNOME,
           DS.NOME,
           DS.DATA_NASCITA,
           DS.RAPPORTO_PARENTELA,
           DS.CODICE_FISCALE,
           CASE
               WHEN DS.STATO >= 1 THEN DS.COMUNE_RESIDENZA
               ELSE AF.COMUNE_RESIDENZA
           END
               AS COMUNE_RESIDENZA,
           CASE
               WHEN DS.STATO >= 1 THEN DS.PROV_RESIDENZA
               ELSE AF.PROV_RESIDENZA
           END
               AS PROV_RESIDENZA,
           CASE
               WHEN DS.STATO >= 1 THEN DS.CAP_RESIDENZA
               ELSE AF.CAP_RESIDENZA
           END
               AS CAP_RESIDENZA,
           DS.COMPAGNIA_AEREA,
           DS.NUMERO_VOLO,
           DS.DATA_VOLO,
           DS.COSTO_TRATTA,
           DS.AEROPORTO_PARTENZA,
           DS.AEROPORTO_PARTENZA_CODICE,
           DS.AEROPORTO_DESTINAZIONE,
           DS.AEROPORTO_DESTINAZIONE_CODICE,
           DS.FILEPATH_BIGLIETTO,
           DS.FILEPATH_CARTAIMBARCO,
           CASE WHEN DS.STATO >= 1 THEN DS.ISEE ELSE D.ISEE END
               AS ISEE,
           CASE
               WHEN DS.STATO >= 1 THEN DS.DATA_RILASCIO_ISEE
               ELSE D.DATA_RILASCIO_ISEE
           END
               AS DATA_RILASCIO_ISEE,
           CASE WHEN DS.STATO >= 1 THEN DS.IBAN ELSE D.IBAN END
               AS IBAN,
           CASE
               WHEN DS.STATO >= 1 THEN DS.ISTITUTO_CREDITO
               ELSE D.ISTITUTO_CREDITO
           END
               AS ISTITUTO_CREDITO,
           CASE
               WHEN DS.STATO >= 1 THEN DS.FILIALE_CREDITO
               ELSE D.FILIALE_CREDITO
           END
               AS FILIALE_CREDITO,
           DS.STATO,
           DS.DATA_REGISTRAZIONE,
           DS.ID_UID_FIREBASE,
           DS.DATA_ESPORTAZIONE,
           DS.DATA_ESITO,
           DS.DATA_EROGAZIONE,
           DS.NOTE,
           CASE
               WHEN DS.STATO >= 1 THEN DS.SCONTO_TOTALE
               ELSE TO_NUMBER (FNGETSCONTO (DS.ID, ''))
           END
               AS SCONTO_TOTALE,
           DS.COMPAGNIA_ID,
           DS.DATA_ACQUISTO,
           DS.LOTTO,
           CASE
               WHEN DS.STATO >= 1 THEN AF.FLAG 
               ELSE DS.FLAG
           END
               AS FLAG,               
           CASE
               WHEN DS.STATO >= 1 THEN AF.PRIORITY 
               ELSE DS.PRIORITY
           END
               AS PRIORITA
      FROM DOMANDA_SCONTI  DS
           INNER JOIN DOMANDA D ON DS.ID_DOMANDA = D.ID
           INNER JOIN ACCOUNT_NUCLEO_FAMILIARE AF
               ON     AF.ID_ACCOUNT = D.ID_ACCOUNT
                  AND DS.CODICE_FISCALE = AF.CODICE_FISCALE;


--
-- VIEW_TRATTE  (View) 
--
--  Dependencies: 
--   AEROPORTI (Table)
--
CREATE OR REPLACE FORCE VIEW VIEW_TRATTE
(A_CODICE, A_NOME, R_CODICE, R_NOME)
BEQUEATH DEFINER
AS 
SELECT A.CODICE AS A_CODICE, A.NOME AS A_NOME, R.CODICE AS R_CODICE, R.NOME AS R_NOME  
FROM AEROPORTI A
CROSS JOIN AEROPORTI R
WHERE A.REGIONE = 19 AND R.REGIONE != 19
UNION
SELECT R.CODICE AS A_CODICE, R.NOME AS A_NOME, A.CODICE AS R_CODICE, A.NOME AS R_NOME  
FROM AEROPORTI R
CROSS JOIN AEROPORTI A
WHERE A.REGIONE = 19 AND R.REGIONE != 19;


--
-- ACCOUNT_ANAGRAFICA_BI  (Trigger) 
--
--  Dependencies: 
--   ACCOUNT_ANAGRAFICA (Table)
--   ACCOUNT_ANAG_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "ACCOUNT_ANAGRAFICA_BI" 
BEFORE INSERT ON ACCOUNT_ANAGRAFICA
FOR EACH ROW
BEGIN
  SELECT ACCOUNT_ANAG_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- ACCOUNT_BI  (Trigger) 
--
--  Dependencies: 
--   ACCOUNT (Table)
--   ACCOUNT_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "ACCOUNT_BI" 
BEFORE INSERT ON ACCOUNT
FOR EACH ROW
BEGIN
  SELECT ACCOUNT_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- ACCOUNT_NUCLEO_BI  (Trigger) 
--
--  Dependencies: 
--   ACCOUNT_NUCLEO_FAMILIARE (Table)
--   ACCOUNT_NUCLEO_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "ACCOUNT_NUCLEO_BI" 
BEFORE INSERT ON ACCOUNT_NUCLEO_FAMILIARE
FOR EACH ROW
BEGIN
  SELECT ACCOUNT_NUCLEO_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- ALLEGATI_BI  (Trigger) 
--
--  Dependencies: 
--   ALLEGATI (Table)
--   ALLEGATI_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "ALLEGATI_BI" 
BEFORE INSERT ON ALLEGATI
FOR EACH ROW
BEGIN
  SELECT ALLEGATI_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- ANAG_COMPAGNIE_TRG  (Trigger) 
--
--  Dependencies: 
--   ANAG_COMPAGNIE (Table)
--   ANAG_COMPAGNIE_SEQ (Sequence)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER ANAG_COMPAGNIE_TRG
BEFORE INSERT
ON ANAG_COMPAGNIE
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
BEGIN
-- For Toad:  Highlight column ID
  :new.ID := ANAG_COMPAGNIE_SEQ.nextval;
END ANAG_COMPAGNIE_TRG;
/


--
-- ANAG_DICHIARAZIONI_BI  (Trigger) 
--
--  Dependencies: 
--   ANAG_DICHIARAZIONI (Table)
--   ANAG_DICHIARAZIONI_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "ANAG_DICHIARAZIONI_BI" 
BEFORE INSERT ON ANAG_DICHIARAZIONI
FOR EACH ROW
BEGIN
  SELECT ANAG_DICHIARAZIONI_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- BANDI_BI  (Trigger) 
--
--  Dependencies: 
--   BANDI (Table)
--   BANDI_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "BANDI_BI" 
BEFORE INSERT ON BANDI
FOR EACH ROW
BEGIN
  SELECT BANDI_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- COMUNE_BI  (Trigger) 
--
--  Dependencies: 
--   COMUNE (Table)
--   COMUNE_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "COMUNE_BI" 
BEFORE INSERT ON COMUNE
FOR EACH ROW
BEGIN
  SELECT COMUNE_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- DOCUMENTIBANDO_BI  (Trigger) 
--
--  Dependencies: 
--   DOCUMENTI_BANDO (Table)
--   DOCUMENTIBANDO_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "DOCUMENTIBANDO_BI" 
BEFORE INSERT ON DOCUMENTI_BANDO
FOR EACH ROW
BEGIN
  SELECT DOCUMENTIBANDO_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- DOMANDA_BI  (Trigger) 
--
--  Dependencies: 
--   DOMANDA (Table)
--   DOMANDA_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "DOMANDA_BI" 
BEFORE INSERT ON DOMANDA
FOR EACH ROW
BEGIN
  SELECT DOMANDA_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- DOMANDA_EMAIL_BI  (Trigger) 
--
--  Dependencies: 
--   DOMANDA_EMAIL (Table)
--   DOMANDA_EMAIL_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER DOMANDA_EMAIL_BI
BEFORE INSERT ON DOMANDA_EMAIL
FOR EACH ROW
BEGIN
  SELECT DOMANDA_EMAIL_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- DOMANDA_SCONTI_BI  (Trigger) 
--
--  Dependencies: 
--   DOMANDA_SCONTI (Table)
--   DOMANDA_SCONTI_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER DOMANDA_SCONTI_BI
BEFORE INSERT ON DOMANDA_SCONTI
FOR EACH ROW
BEGIN
  SELECT DOMANDA_SCONTI_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- ESPORTAZIONI_TRG  (Trigger) 
--
--  Dependencies: 
--   ESPORTAZIONI (Table)
--   ESPORTAZIONI_SEQ (Sequence)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER ESPORTAZIONI_TRG
BEFORE INSERT
ON ESPORTAZIONI
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
BEGIN
-- For Toad:  Highlight column LOTTO
  :new.LOTTO := ESPORTAZIONI_SEQ.nextval;
END ESPORTAZIONI_TRG;
/


--
-- FAQ_BI  (Trigger) 
--
--  Dependencies: 
--   FAQ (Table)
--   FAQ_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "FAQ_BI" 
BEFORE INSERT ON FAQ
FOR EACH ROW
BEGIN
  SELECT FAQ_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- FAQ_UTENTI_BI  (Trigger) 
--
--  Dependencies: 
--   FAQ_UTENTI (Table)
--   FAQ_UTENTI_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "FAQ_UTENTI_BI" 
BEFORE INSERT ON FAQ_UTENTI
FOR EACH ROW
BEGIN
  SELECT FAQ_UTENTI_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- LOGS_BE_BI  (Trigger) 
--
--  Dependencies: 
--   LOGS_BE (Table)
--   LOGS_BE_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER LOGS_BE_BI 
BEFORE INSERT ON LOGS_BE
FOR EACH ROW
BEGIN
  SELECT LOGS_BE_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- LOGS_BI  (Trigger) 
--
--  Dependencies: 
--   LOGS (Table)
--   LOGS_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER LOGS_BI 
BEFORE INSERT ON LOGS
FOR EACH ROW
BEGIN
  SELECT LOGS_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- LOGS_P7M_BI  (Trigger) 
--
--  Dependencies: 
--   LOGS_P7M (Table)
--   LOGS_P7M_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER LOGS_P7M_BI 
BEFORE INSERT ON LOGS_P7M
FOR EACH ROW
BEGIN
  SELECT LOGS_P7M_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- SPID_ACCESSI_BI  (Trigger) 
--
--  Dependencies: 
--   SPID_ACCESSI (Table)
--   SPID_ACCESSI_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "SPID_ACCESSI_BI" 
BEFORE INSERT ON SPID_ACCESSI
FOR EACH ROW
BEGIN
  SELECT SPID_ACCESSI_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- UID_FIREBASE_ADMIN_BI  (Trigger) 
--
--  Dependencies: 
--   UID_FIREBASE_ADMIN (Table)
--   UID_FIREBASE_ADMIN_ID_SEQ (Sequence)
--   DUAL (Synonym)
--   STANDARD (Package)
--
CREATE OR REPLACE TRIGGER "UID_FIREBASE_ADMIN_BI" 
BEFORE INSERT ON UID_FIREBASE_ADMIN
FOR EACH ROW
BEGIN
  SELECT UID_FIREBASE_ADMIN_ID_SEQ.nextval
  INTO :new.ID
  FROM dual;
END;
/


--
-- AEROPORTI_COMPAGNIE  (Table) 
--
--  Dependencies: 
--   AEROPORTI (Table)
--   ANAG_COMPAGNIE (Table)
--
--   Row Count: 78
CREATE TABLE AEROPORTI_COMPAGNIE
(
  AEROPORTO  VARCHAR2(3 BYTE),
  COMPAGNIA  INTEGER
)
TABLESPACE BANDO_VOLI
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );


--
-- AERO_COMP_PK  (Index) 
--
--  Dependencies: 
--   AEROPORTI_COMPAGNIE (Table)
--
CREATE UNIQUE INDEX AERO_COMP_PK ON AEROPORTI_COMPAGNIE
(AEROPORTO, COMPAGNIA)
TABLESPACE BANDO_VOLI
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           );

ALTER TABLE AEROPORTI_COMPAGNIE ADD (
  CONSTRAINT AERO_COMP_PK
  PRIMARY KEY
  (AEROPORTO, COMPAGNIA)
  USING INDEX AERO_COMP_PK
  ENABLE VALIDATE);



--
-- SPAEROCOMPAGNIESAVE  (Procedure) 
--
--  Dependencies: 
--   AEROPORTI_COMPAGNIE (Table)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SPAEROCOMPAGNIESAVE" 
(
    P_AEROPORTO  VARCHAR2,
    P_COMPAGNIA  INT 
) AS 
INSUPDATE  NUMBER;
BEGIN

SELECT COUNT(*) INTO INSUPDATE  FROM AEROPORTI_COMPAGNIE WHERE AEROPORTO = P_AEROPORTO AND COMPAGNIA = P_COMPAGNIA;

IF INSUPDATE <= 0 THEN
        INSERT INTO AEROPORTI_COMPAGNIE (AEROPORTO, COMPAGNIA) VALUES (P_AEROPORTO, P_COMPAGNIA);
END IF;

END SPAEROCOMPAGNIESAVE;
/


--
-- SPESPORTASCONTI  (Procedure) 
--
--  Dependencies: 
--   ACCOUNT_NUCLEO_FAMILIARE (Table)
--   DOMANDA (Table)
--   DOMANDA_SCONTI (Table)
--   FNGETSCONTO (Function)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE "SPESPORTASCONTI" 
(
  P_ID  INT,
  P_NUM_LOTTO INT
) AS 
CTR_STATO INT;
CTR_PRES_ACC INT;
T_ID_DOMANDA INT;
T_ID_ACCOUNT INT;
T_BENEFICIARIO VARCHAR2(255);
T_COMUNE_RESIDENZA VARCHAR2(255);
T_PROV_RESIDENZA  VARCHAR2(2);
T_CAP_RESIDENZA  VARCHAR2(5);
T_FLAG VARCHAR2(1000);
T_ISEE INT;
T_PRIORITY INT;
T_DATA_RILASCIO_ISEE DATE;
T_IBAN VARCHAR2(255);
T_ISTITUTO_CREDITO VARCHAR2(255);
T_FILIALE_CREDITO VARCHAR2(255);
T_SCONTO_TOTALE NUMBER;
BEGIN
CTR_PRES_ACC :=0;

SELECT STATO, ID_DOMANDA, CODICE_FISCALE INTO CTR_STATO, T_ID_DOMANDA, T_BENEFICIARIO FROM DOMANDA_SCONTI WHERE ID = P_ID;
/*Verifico la presenza del beneficiario nel nucleo familiare*/
--SELECT NVL(ID,0) INTO CTR_PRES_ACC FROM ACCOUNT_NUCLEO_FAMILIARE WHERE CODICE_FISCALE = T_BENEFICIARIO;  

SELECT COUNT(*) INTO CTR_PRES_ACC FROM ACCOUNT_NUCLEO_FAMILIARE WHERE CODICE_FISCALE = T_BENEFICIARIO;
    
IF CTR_STATO = 0 AND CTR_PRES_ACC > 0 THEN
     
    SELECT 
        ID_ACCOUNT,ISEE,DATA_RILASCIO_ISEE,IBAN,ISTITUTO_CREDITO,FILIALE_CREDITO
        INTO 
        T_ID_ACCOUNT,T_ISEE,T_DATA_RILASCIO_ISEE,T_IBAN,T_ISTITUTO_CREDITO,T_FILIALE_CREDITO
    FROM DOMANDA WHERE ID = T_ID_DOMANDA; 
    SELECT 
        COMUNE_RESIDENZA,PROV_RESIDENZA,CAP_RESIDENZA, FLAG, PRIORITY
        INTO 
        T_COMUNE_RESIDENZA,T_PROV_RESIDENZA,T_CAP_RESIDENZA,T_FLAG, T_PRIORITY
    FROM ACCOUNT_NUCLEO_FAMILIARE WHERE CODICE_FISCALE = T_BENEFICIARIO AND ID_ACCOUNT = T_ID_ACCOUNT; 
    
    T_SCONTO_TOTALE := TO_NUMBER(FNGETSCONTO(P_ID, ''));

    UPDATE DOMANDA_SCONTI SET 
        COMUNE_RESIDENZA = T_COMUNE_RESIDENZA, 
        PROV_RESIDENZA = T_PROV_RESIDENZA, 
        CAP_RESIDENZA = T_CAP_RESIDENZA,        
        FLAG = T_FLAG,        
        ISEE = T_ISEE,
        DATA_RILASCIO_ISEE = T_DATA_RILASCIO_ISEE,
        IBAN = T_IBAN,
        ISTITUTO_CREDITO = T_ISTITUTO_CREDITO,
        FILIALE_CREDITO = T_FILIALE_CREDITO,
        STATO = 1,    
        DATA_ESPORTAZIONE = SYSTIMESTAMP,
        SCONTO_TOTALE = T_SCONTO_TOTALE,
        LOTTO = P_NUM_LOTTO, 
        PRIORITY = T_PRIORITY        
    WHERE ID = P_ID; 
END IF;


END SPESPORTASCONTI;
/


--
-- SPPRESAINCARICO  (Procedure) 
--
--  Dependencies: 
--   DOMANDA_SCONTI (Table)
--   ESPORTAZIONI (Table)
--   ESPORTAZIONI_SEQ (Sequence)
--   SPESPORTASCONTI (Procedure)
--   DUAL (Synonym)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE PROCEDURE SPPRESAINCARICO (
    DATA_INIZIO IN DATE,
    DATA_FINE IN DATE
) AS
    -- Dichiarazione delle variabili
    V_ID DOMANDA_SCONTI.ID%TYPE;
    V_NUM_LOTTO INT;

    -- Cursor per la SELECT
    CURSOR C_CURSOR IS
        SELECT ID
        FROM DOMANDA_SCONTI
        WHERE DATA_REGISTRAZIONE BETWEEN DATA_INIZIO AND DATA_FINE AND STATO = 0;

BEGIN
    INSERT INTO ESPORTAZIONI (LOTTO) VALUES (0);
    
    SELECT ESPORTAZIONI_SEQ.CURRVAL INTO V_NUM_LOTTO FROM DUAL;
    
    -- Apertura del cursore
    OPEN C_CURSOR;  
    

    -- Loop attraverso i risultati della SELECT
    LOOP
        -- Recupero dei valori dalla riga corrente
        FETCH C_CURSOR INTO V_ID;

        -- Uscita dal loop quando non ci sono più righe
        EXIT WHEN C_CURSOR%NOTFOUND;

        -- Chiamata alla funzione con i valori recuperati
        SPESPORTASCONTI(V_ID, V_NUM_LOTTO);

    END LOOP;

    -- Chiusura del cursore
    CLOSE C_CURSOR;
END SPPRESAINCARICO;
/


--
-- CALCOLAETA  (Function) 
--
--  Dependencies: 
--   ACCOUNT_NUCLEO_FAMILIARE (Table)
--   GETPERIODOANNIMESIGIORNI (Function)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE FUNCTION CALCOLAETA (
P_CF IN VARCHAR2,
P_END_DATA IN VARCHAR2
)
RETURN number IS
    ETA number;
    END_DATA_CALCOLO date;
BEGIN 
    ETA := 0;-- Punti per Età    
    END_DATA_CALCOLO := TO_DATE(P_END_DATA,'dd/mm/YYYY hh24:mi:ss');-- Data definita dall'accordo sindacale
    
    -- Calcolo del punteggio per anzianità di posizione
    --SELECT (ROUND((END_DATA_CALCOLO - DATA_NASCITA)/365))
    SELECT GETPERIODOANNIMESIGIORNI(DATA_NASCITA, END_DATA_CALCOLO, 'ANNI') 
    INTO ETA
    from ACCOUNT_NUCLEO_FAMILIARE where CODICE_FISCALE = P_CF;
    
    IF ETA IS NULL THEN
        ETA := 0;    
    END IF;

    RETURN ETA;
END;
/


--
-- CALCOLAETAFROMTODATE  (Function) 
--
--  Dependencies: 
--   GETPERIODOANNIMESIGIORNI (Function)
--   DUAL (Synonym)
--   STANDARD (Package)
--   SYS_STUB_FOR_PURITY_ANALYSIS (Package)
--
CREATE OR REPLACE FUNCTION CALCOLAETAFROMTODATE (
P_START_DATA IN VARCHAR2,
P_END_DATA IN VARCHAR2
)
RETURN number IS
    ETA number;
    START_DATA_CALCOLO date;
    END_DATA_CALCOLO date;
BEGIN 
    ETA := 0;-- Punti per Età
    START_DATA_CALCOLO := TO_DATE(P_START_DATA,'dd/mm/YYYY hh24:mi:ss');-- Data definita dall'accordo sindacale    
    END_DATA_CALCOLO := TO_DATE(P_END_DATA,'dd/mm/YYYY hh24:mi:ss');-- Data definita dall'accordo sindacale
    
    -- Calcolo del punteggio per anzianità di posizione
    --SELECT (ROUND((END_DATA_CALCOLO - DATA_NASCITA)/365))
    SELECT GETPERIODOANNIMESIGIORNI(START_DATA_CALCOLO, END_DATA_CALCOLO, 'ANNI') 
    INTO ETA
    from DUAL;
    
    IF ETA IS NULL THEN
        ETA := 0;    
    END IF;

    RETURN ETA;
END;
/


ALTER TABLE ACCOUNT_NUCLEO_FAMILIARE ADD (
  CONSTRAINT FK_ACCOUNT_NUCLEO 
  FOREIGN KEY (ID_ACCOUNT) 
  REFERENCES ACCOUNT (ID)
  ENABLE VALIDATE);


ALTER TABLE DOMANDA ADD (
  CONSTRAINT ACCOUNT_DOMANDA_R01 
  FOREIGN KEY (ID_ACCOUNT) 
  REFERENCES ACCOUNT (ID)
  ENABLE VALIDATE);


ALTER TABLE DOMANDA_EMAIL ADD (
  FOREIGN KEY (ID_DOMANDA) 
  REFERENCES DOMANDA (ID)
  ENABLE VALIDATE);


ALTER TABLE DOMANDA_SCONTI ADD (
  FOREIGN KEY (ID_DOMANDA) 
  REFERENCES DOMANDA (ID)
  ENABLE VALIDATE);


ALTER TABLE AEROPORTI_COMPAGNIE ADD (
  CONSTRAINT AEROPORTI_COMPAGNIE_R01 
  FOREIGN KEY (AEROPORTO) 
  REFERENCES AEROPORTI (CODICE)
  ENABLE VALIDATE);

ALTER TABLE AEROPORTI_COMPAGNIE ADD (
  CONSTRAINT AEROPORTI_COMPAGNIE_R02 
  FOREIGN KEY (COMPAGNIA) 
  REFERENCES ANAG_COMPAGNIE (ID)
  ENABLE VALIDATE);
