
/*------ ATD 285317 ------*/

DECLARE v_Count NUMBER(1) := 0;
BEGIN
SELECT 1 INTO v_Count FROM USER_TAB_COLUMNS WHERE Table_Name = 'ITNFSAICOMPLEMENTO' AND Column_Name = 'CENQIPI';
EXCEPTION WHEN NO_DATA_FOUND THEN
EXECUTE IMMEDIATE 'ALTER TABLE ITNFSAICOMPLEMENTO ADD CENQIPI CHAR(3)';
END;
/

DECLARE v_Count NUMBER(1) := 0;
BEGIN
SELECT 1 INTO v_Count FROM USER_TAB_COLUMNS WHERE Table_Name = 'ITNFENTCOMPLEMENTO' AND Column_Name = 'CENQIPI';
EXCEPTION WHEN NO_DATA_FOUND THEN
EXECUTE IMMEDIATE 'ALTER TABLE ITNFENTCOMPLEMENTO ADD CENQIPI CHAR(3)';
END;
/

DECLARE v_Count NUMBER(1) := 0;
BEGIN
SELECT 1 INTO v_Count FROM USER_TAB_COLUMNS WHERE Table_Name = 'DADOSITEMNFE' AND Column_Name = 'CENQIPI';
EXCEPTION WHEN NO_DATA_FOUND THEN
EXECUTE IMMEDIATE 'ALTER TABLE DADOSITEMNFE ADD CENQIPI CHAR(3)';
END;
/

DECLARE v_count NUMBER:=0;
BEGIN
SELECT 1 INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'CODIGOENQIPI' ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE CODIGOENQIPI(
       CODIGO CHAR(3) NOT NULL,
       GRUPOCST VARCHAR2(100),
       DESCRICAO VARCHAR2(500)
)';
EXECUTE IMMEDIATE 'alter table CODIGOENQIPI ADD CONSTRAINT PK_CODIGOENQIPI PRIMARY KEY (CODIGO)'; 
END;
END;
/ 
