CREATE TABLE TRAB_RETIRADAOP (
    CDFILIAL VARCHAR2(4), 
    NRRETEST  VARCHAR2(10),
    NRORDPROD VARCHAR2(10), 
    NRSUBORDPROD VARCHAR2(2),
    CDPRODINSUMO VARCHAR2(10), 
    STATUS CHAR(1), 
    CDOPERADOR VARCHAR2(12), 
    DTRETIRADA DATE,
    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_INCONSPEDIDO CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE TRAB_RETIRADAOP ADD CONSTRAINT PK_TRAB_RETIRADAOP PRIMARY KEY (CDFILIAL, NRRETEST, NRORDPROD, NRSUBORDPROD, CDPRODINSUMO)
/
ALTER TABLE PARAMAN ADD IDVALRETDUPLICADA VARCHAR2(1) NULL
   CONSTRAINT CKC_IDVALRETDUPLICADA CHECK (IDVALRETDUPLICADA IS NULL OR (IDVALRETDUPLICADA IN ('S','N')))
/