CREATE TABLE PARAMMOVEST  
( 
    CDCOLUNAMOVEST      VARCHAR2(2)            NOT NULL,
    NMCOLUNAMOVEST      VARCHAR2(30)           NOT NULL,
    CDTPRETIMOVEST      VARCHAR2(2)            NOT NULL,
		CONSTRAINT PK_PARAMMOVEST PRIMARY KEY (CDCOLUNAMOVEST, CDTPRETIMOVEST),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_PARAMMOVEST CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          DATE                  			NULL,
    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'
)
/

CREATE INDEX EST00624_FK ON PARAMMOVEST (CDTPRETIMOVEST ASC)
/
ALTER TABLE PARAMMOVEST
    ADD CONSTRAINT FKEST00624_PARAMMOVEST FOREIGN KEY  (CDTPRETIMOVEST)
       REFERENCES TIPORETI (CDTIPORETI)
/

-- Insercao de valores na tabela

BEGIN
FOR C_TIPO IN (SELECT CDTIPORETI
FROM TIPORETI
WHERE CDTIPORETI IN ('01','02','03','04','05'))
LOOP
IF C_TIPO.CDTIPORETI = '01' THEN
INSERT INTO PARAMMOVEST
(CDCOLUNAMOVEST, NMCOLUNAMOVEST, CDTPRETIMOVEST)
VALUES
('QU', 'QUEBRA', '01');
END IF;

IF C_TIPO.CDTIPORETI = '02' THEN
INSERT INTO PARAMMOVEST
(CDCOLUNAMOVEST, NMCOLUNAMOVEST, CDTPRETIMOVEST)
VALUES
('QU', 'QUEBRA', '02');
END IF;

IF C_TIPO.CDTIPORETI = '03' THEN
INSERT INTO PARAMMOVEST
(CDCOLUNAMOVEST, NMCOLUNAMOVEST, CDTPRETIMOVEST)
VALUES
('QU', 'QUEBRA', '03');
END IF;

IF C_TIPO.CDTIPORETI = '04' THEN
INSERT INTO PARAMMOVEST
(CDCOLUNAMOVEST, NMCOLUNAMOVEST, CDTPRETIMOVEST)
VALUES
('VE', 'VENDAS', '04');
END IF;

IF C_TIPO.CDTIPORETI = '05' THEN
INSERT INTO PARAMMOVEST
(CDCOLUNAMOVEST, NMCOLUNAMOVEST, CDTPRETIMOVEST)
VALUES
('CO', 'CONSUMO FUNC', '05');
END IF;

COMMIT;
END LOOP;
END;
/