
/*------ ATD 307522 ------*/
DECLARE v_count NUMBER:=0;
BEGIN
	SELECT 1 INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'NFMANUALCHAVEACESSO' ;
	EXCEPTION
	WHEN NO_DATA_FOUND THEN
	BEGIN
		EXECUTE IMMEDIATE 'create table NFMANUALCHAVEACESSO (
		ID INT NOT NULL,
		FILIAL VARCHAR(2),
	    NUMNOTA VARCHAR(13),
	    SERIE VARCHAR(3),
	    CHAVEACESSO VARCHAR(44))';
		EXECUTE IMMEDIATE 'ALTER TABLE NFMANUALCHAVEACESSO ADD CONSTRAINT PK_NFMANUALCHAVEACESSO PRIMARY KEY (ID)';
		EXECUTE IMMEDIATE 'CREATE SEQUENCE NFMANUALCHAVEACESSO_SEQ MINVALUE 1 MAXVALUE 
		999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER';
		EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER NFMANUALCHAVEACESSO_I
		BEFORE INSERT ON NFMANUALCHAVEACESSO for each ROW
		WHEN (new.ID IS NULL)
		BEGIN
		SELECT NFMANUALCHAVEACESSO_SEQ.NEXTVAL INTO :new.ID FROM dual;
		END;';
	END;
END;