
/*------ ATD 416488 ------*/
-- PA 416488 - Oracle

DECLARE v_count NUMBER:=0;

BEGIN
	SELECT Count(1) INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'RELACIONADEVOLUCAOTRANSFERENCIA';
	IF v_count = 0 THEN

		EXECUTE IMMEDIATE 'CREATE TABLE RELACIONADEVOLUCAOTRANSFERENCIA(
		ID NUMBER(10) NOT NULL,
		NUMORDDEV NUMBER(10) NOT NULL,
		NUMORDTRANSF NUMBER(10) NOT NULL)';

		EXECUTE IMMEDIATE 'ALTER TABLE RELACIONADEVOLUCAOTRANSFERENCIA ADD CONSTRAINT PK_RelacionaDevolucaoTransferencia PRIMARY KEY (ID)';

		BEFORE INSERT ON RELACIONADEVOLUCAOTRANSFERENCIA FOR EACH ROW

		WHEN (new.ID IS NULL)

		BEGIN
			SELECT RELACIONADEVOLUCAOTRANSFERENCIA.NEXTVAL INTO :new.ID FROM dual;
		END;

	END IF;

END;
