Array
(
)

Criando um LOOP com FOR REVERSE no PL/SQL Oracle

Edigleyson Rocha
   - 03 mar 2017

CREATE TABLE SQM_TABLE_TESTE (
ID NUMBER GENERATED ALWAYS AS IDENTITY,
QTMR VARCHAR2(50),
DESCRICAO VARCHAR2(100)
);

DECLARE
V_QTMR VARCHAR2(50);
V_COUNT INTEGER;

BEGIN
V_COUNT := 0;

FOR V_COUNT IN REVERSE 1..100

LOOP

SELECT 'QTMR'||TO_CHAR((NVL(MAX(ID),0)+1),'FM00000000')
INTO V_QTMR
FROM SQM_TABLE_TESTE;
INSERT INTO SQM_TABLE_TESTE (QTMR,DESCRICAO)
VALUES (V_QTMR,'EDIGLEYSON'||'-'||V_QTMR);
END LOOP;

END;
SELECT * FROM SQM_TABLE_TESTE;