How to do WHILE in PL/SQL

Asked

Viewed 4,728 times

1

I need to make a WHILE in SQL. Follow the code I’ve tried

DECLARE CONT INT;
SET CONT=0;

WHILE CONT < 3
BEGIN
SELECT CONT   
SET  CONT = CONT +1;
END;

The error that arises is as follows:

Erro a partir da linha : 1 no comando - DECLARE CONT INT; SET CONT=0;    
WHILE CONT < 3 BEGIN SELECT CONT    SET  CONT = CONT +1; END; Relatório de
erros - ORA-06550: linha 2, coluna 9: PLS-00103: Encontrado o símbolo "="
quando um dos seguintes símbolos era esperado:

  := . ( @ % ; not nulo faixa default caractere
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

2 answers

0


Friend by the bug report you put you are using Oracle and its syntax is a little different to write a while.

Try it this way:

DECLARE CONT INTEGER := 0;
BEGIN
 WHILE CONT < 3 LOOP
   SET CONT := CONT + 1;
 END LOOP;
END;

-1

DECLARE CONT INT SET CONT=0;

WHILE CONT < 3 DO BEGIN SELECT CONT
SET CONT = CONT +1; END WHILE;

In MYSQL

  • 1

    The question is about PL/SQL and Oracle, not Mysql.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.