
/*------ ATD 265320 ------*/
DECLARE v_count NUMBER(1) := 0;
BEGIN
	SELECT 1 INTO v_count FROM USER_TAB_COLUMNS WHERE table_name = 'ITEMPREVIA' AND column_name = 'ITEM';
	EXCEPTION 
	WHEN NO_DATA_FOUND THEN 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE ITEMPREVIA ADD ITEM INTEGER DEFAULT 0 NOT NULL';
     EXECUTE IMMEDIATE 'CREATE SEQUENCE ITEMPREVIA_SEQ MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER' ;
     EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER ITEMPREVIA_I
        BEFORE INSERT ON ITEMPREVIA for each ROW
        WHEN (new.ITEM IS NULL)
            BEGIN
                SELECT ITEMPREVIA_SEQ.NEXTVAL INTO :new.ITEM FROM dual;
            END;';
     END;
END;
/