
/*------ ATD 368355 ------*/
DECLARE v_count NUMBER:=0;

BEGIN

SELECT Count(1) INTO v_count FROM USER_TAB_COLUMNS WHERE UPPER(table_name) = 'BASECALFAT' and UPPER(column_name) = 'CODIGOCEST';

IF v_count = 0 THEN

EXECUTE IMMEDIATE 'ALTER TABLE BASECALFAT ADD CODIGOCEST CHAR(14) DEFAULT '''' NOT NULL';

END IF;

SELECT Count(1) INTO v_count FROM USER_TAB_COLUMNS WHERE UPPER(table_name) = 'ITNFSAICAD' and UPPER(column_name) = 'IDCODREDBASE';

IF v_count = 0 THEN

EXECUTE IMMEDIATE 'ALTER TABLE ITNFSAICAD ADD IDCODREDBASE INT NULL';

END IF;

SELECT Count(1) INTO v_count FROM USER_TAB_COLUMNS WHERE UPPER(table_name) = 'ITNFENTCAD' and UPPER(column_name) = 'IDCODREDBASE';

IF v_count = 0 THEN

EXECUTE IMMEDIATE 'ALTER TABLE ITNFENTCAD ADD IDCODREDBASE INT NULL';

END IF;

END;
/*------ ATD 412290 ------*/
DECLARE v_count NUMBER:=0;
BEGIN
SELECT Count(1) INTO v_count FROM USER_TAB_COLUMNS WHERE UPPER(table_name) = 'BASECALFAT' and UPPER(column_name) = 'ID';
IF v_count = 0 THEN
EXECUTE IMMEDIATE 'ALTER TABLE BASECALFAT ADD ID NUMBER(10) NULL';
EXECUTE IMMEDIATE 'ALTER TABLE BASECALFAT ADD CONSTRAINT PK_BASECALFAT PRIMARY KEY (ID)';
EXECUTE IMMEDIATE 'CREATE BASECALFAT_SEQ MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER' ;
EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER BASECALFAT_I
BEFORE INSERT ON BASECALFAT FOR EACH ROW
WHEN (new.ID IS NULL)
BEGIN
SELECT BASECALFAT_SEQ.NEXTVAL INTO :new.ID FROM dual;
END;';
END IF;
END;
