0
votes

boucle for à insérer dans la table des mails

BEGIN
  FOR l_counter IN 1..10
  LOOP
    insert into mails
    VALUES (i);
    --continue WHEN 6 AND 8;
  END LOOP;
  commit;
END;

0 commentaires

3 Réponses :


0
votes

Avez-vous besoin ci-dessous -

BEGIN
  FOR l_counter IN 1..10
  LOOP
    IF l_counter IN (6, 8) THEN
        CONTINUE;
    END IF;
    insert into mails
    VALUES (l_counter);
  END LOOP;
  commit;
END;


0 commentaires

1
votes

En effet, vous n'avez pas besoin d'un bloc PL / SQL, l'utilisation d'un SQL-Insert suffit comme

SQL> insert into mails
select * from
(
  select level as lvl
    from dual
 connect by level <= 10
)
where lvl not in (6,8);

SQL> commit;


0 commentaires

4
votes

Vous pouvez faire

MERGE INTO MAILS m
  USING (SELECT LEVEL AS N
           FROM DUAL
           WHERE LEVEL NOT IN (6,8)
           CONNECT BY LEVEL <= 10) d
    ON (m.VAL = d.N)
  WHEN NOT MATCHED THEN
    INSERT VALUES (N);

ou simplement dire

INSERT INTO MAILS
  SELECT LEVEL
    FROM DUAL
    WHERE LEVEL NOT IN (6,8)
    CONNECT BY LEVEL <= 10

Ou il y a toujours

BEGIN
  FOR n IN 1..10 LOOP
    IF n NOT IN (6,8) THEN
      insert into mails
      VALUES (n);
    END IF;
  END LOOP;

  commit;
END;


1 commentaires

bonne prise..! Quand j'ai considéré connecter par niveau <= 10 et niveau pas dans (6,8) qui a échoué et j'ai abandonné cette option sans sous-requête, voyez maintenant que vous avez pris clause...