
/*------ ATD 338342 ------*/
DECLARE v_count NUMBER:=0;
BEGIN
SELECT Count(1) INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'CANCELAMENTOLOCALFISICO';
IF v_count = 0 THEN
EXECUTE IMMEDIATE 'CREATE TABLE CANCELAMENTOLOCALFISICO(
				ID INT NOT NULL,
				NUMORD INT NOT NULL, 
				ITEM CHAR(5) NOT NULL, 
				CODPRO CHAR(5) NOT NULL,
				LOTEINTERNO CHAR(7) NOT NULL,
				LOCALFISICO CHAR(5) NOT NULL,
				QUANTIDADE NUMERIC(13,3) NULL)';
EXECUTE IMMEDIATE 'ALTER TABLE CANCELAMENTOLOCALFISICO ADD CONSTRAINT PK_CANCELAMENTOLOCALFISICO PRIMARY KEY (ID)';
EXECUTE IMMEDIATE 'CREATE SEQUENCE CANCELAMENTOLOCALFISICO_SEQ MINVALUE 1 MAXVALUE 
		999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER';
EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER CANCELAMENTOLOCALFISICO_I
		BEFORE INSERT ON CANCELAMENTOLOCALFISICO for each ROW
		WHEN (new.ID IS NULL)
		BEGIN
		SELECT CANCELAMENTOLOCALFISICO_SEQ.NEXTVAL INTO :new.ID FROM dual;
		END;';
END IF;
END;
/