CREATE TABLE IDEAL_4FORN
( 
  NRIDEAL4FORN        NUMBER,
  NRSEQEMISSAO        VARCHAR2(10),
  NRPAGINA            NUMBER,
  CDREGIAO            VARCHAR2(3),
  NMREGIAO            VARCHAR2(30),
  NMOPERADOR          VARCHAR2(40),
  CDOPERADOR          VARCHAR2(12),
  CDPRODUTO           VARCHAR2(10),
  NMPRODUTO           VARCHAR2(50),
  CDARVPROD           VARCHAR2(20),
  SGUNIDADE           VARCHAR2(10),
  CDMARCA             VARCHAR2(5),
  NMMARCA             VARCHAR2(20),
  DTINI               DATE,
  DTFIN               DATE,
  NMFANTFORN_AF_ANT   VARCHAR2(40),
  IDTPIJURFORN_AF_ANT VARCHAR2(1),
  NRINSJURFORN_AF_ANT VARCHAR2(20),
  VRPREUNIAF_AF_ANT   FLOAT(126),
  QTACOMPRAR          FLOAT(126),
  NMFANTFORN_MIX      VARCHAR2(40),
  IDTPIJURFORN_MIX    VARCHAR2(1),
  NRINSJURFORN_MIX    VARCHAR2(20),
  VRPRECUNIITM_MIX    FLOAT(126),
  VRPRECENT_MIX       FLOAT(126),
  VALOR_TORAL_MIX     FLOAT(126),
  CDMARCA_MIX         VARCHAR2(5),
  NMMARCA_MIX         VARCHAR2(20),
  NMFANTFORN1         VARCHAR2(40),
  CDFORNECED1         VARCHAR2(21),
  IDTPIJURFORN1       VARCHAR2(1),
  NRINSJURFORN1       VARCHAR2(20),
  VRTOTAL_FORN1       FLOAT(126),
  VRPRECUNIITM1       FLOAT(126),
  VALOR_TORAL_ITM1    FLOAT(126),
  VRPRECENT1          FLOAT(126),
  NMFANTFORN2         VARCHAR2(40),
  CDFORNECED2         VARCHAR2(21),
  IDTPIJURFORN2       VARCHAR2(1),
  NRINSJURFORN2       VARCHAR2(20),
  VRTOTAL_FORN2       FLOAT(126),
  VRPRECUNIITM2       FLOAT(126),
  VALOR_TORAL_ITM2    FLOAT(126),
  VRPRECENT2          FLOAT(126),
  NMFANTFORN3         VARCHAR2(40),
  CDFORNECED3         VARCHAR2(21),
  IDTPIJURFORN3       VARCHAR2(1),
  NRINSJURFORN3       VARCHAR2(20),
  VRTOTAL_FORN3       FLOAT(126),
  VRPRECUNIITM3       FLOAT(126),
  VALOR_TORAL_ITM3    FLOAT(126),
  VRPRECENT3          FLOAT(126),
  NMFANTFORN4         VARCHAR2(40),
  CDFORNECED4         VARCHAR2(21),
  IDTPIJURFORN4       VARCHAR2(1),
  NRINSJURFORN4       VARCHAR2(20),
  VRTOTAL_FORN4       FLOAT(126),
  VRPRECUNIITM4       FLOAT(126),
  VALOR_TORAL_ITM4    FLOAT(126),
  VRPRECENT4          FLOAT(126), 
	CONSTRAINT PK_IDEAL_4FORN PRIMARY KEY(NRIDEAL4FORN),
  NRORG             NUMBER 	      	DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
  IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
  DTINCLUSAO        DATE            DEFAULT SYSDATE,
  DTULTATU          DATE            DEFAULT SYSDATE,
  NRORGINCLUSAO     NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
  CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 					NULL,
  NRORGULTATU       NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
  CDOPERULTATU      VARCHAR2(12)    DEFAULT '1',
	CONSTRAINT CKC_IDATIVO_IDEAL_4FORN CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE IDEAL_4FORN ADD CONSTRAINT IDEAL_4FORN_CB UNIQUE (NRSEQEMISSAO, NRPAGINA, CDREGIAO, CDOPERADOR, CDPRODUTO)
/