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

BEGIN

SELECT Count(1) INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'CARACTERISTICA_ECOMMERCE_CATALOGO';

IF v_count = 0 THEN

EXECUTE IMMEDIATE 'CREATE TABLE CARACTERISTICA_ECOMMERCE_CATALOGO(
        ID INT NOT NULL,
        CODIGO VARCHAR2(20) NOT NULL, 
        NOME VARCHAR2(50) NOT NULL)';
EXECUTE IMMEDIATE 'ALTER TABLE CARACTERISTICA_ECOMMERCE_CATALOGO ADD CONSTRAINT PK_CARACTERISTICA_ECOMMERCE_CATALOGO PRIMARY KEY (ID)';
EXECUTE IMMEDIATE 'CREATE CARACTERISTICA_ECOMMERCE_CATALOGO_IDX1 ON CARACTERISTICA_ECOMMERCE_CATALOGO(CODIGO)';
EXECUTE IMMEDIATE 'CREATE SEQUENCE CARACTERISTICA_ECOMMERCE_CATALOGO_SEQ MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER' ;
EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER CARACTERISTICA_ECOMMERCE_CATALOGO_I
BEFORE INSERT ON CARACTERISTICA_ECOMMERCE_CATALOGO FOR EACH ROW
WHEN (new.ID IS NULL)
BEGIN
SELECT CARACTERISTICA_ECOMMERCE_CATALOGO_SEQ.NEXTVAL INTO :new.ID FROM dual;
END;';

END IF;

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

IF v_count = 0 THEN

EXECUTE IMMEDIATE 'ALTER TABLE CARACTERISTICA_ECOMMERCE ADD IDCARACTERISTICACATALOGO INT';

END IF;

END;
/
/*------ ATD 466536 ------*/
-- Adicionando coluna SEMCBENEF na tabela BASECALFAT
IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS WHERE name = 'SEMCBENEF' and syscolumns.id IN (SELECT ID FROM SYSOBJECTS WHERE xtype='U' AND name='BASECALFAT')) 
ALTER TABLE BASECALFAT ADD SEMCBENEF NUMERIC(1,0)
go
