Skip a fetch from the for / loop

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
dudu0566
Rank: Analista Júnior
Rank: Analista Júnior
Posts: 74
Joined: Mon, 06 Aug 2007 3:59 pm
Location: Campinas - SP

I would like to know if you have any command that I can use inside a for / loop to jump to the next fetch.
I know that the Exit command interrupts the execution of the for / loop, I would only like that fetch was discarded.

Select all

 
for x in 0..10 
loop 
   if x = 4 then 
   <PULAR ESTE FETCH> 
   end if; 
   ... 
   ... 
 end loop 

grateful
Eduardo Gomes
Trevisolli
Moderador
Moderador
Posts: 2016
Joined: Wed, 12 Jan 2005 3:25 pm
Location: Araraquara - SP
Abraço,

Trevisolli
OCA Oracle PL/SQL Developer Certified Associate
OCP Oracle Forms Developer Certified Professional
Araraquara-SP

Brother,

By your code (FORM), you do not need FETCH.
He is implicit.

Just use your condition inside the expression.
dudu0566
Rank: Analista Júnior
Rank: Analista Júnior
Posts: 74
Joined: Mon, 06 Aug 2007 3:59 pm
Location: Campinas - SP

Trevisolli may not express my question right.

What I want to know, as if within a loop I can skip that item and go to the next loop item.
For example the loop goes from 1 to 10, inside has some programming, but when it is 4 is not to perform, that is, from 1 to 3 it makes the normal loop, in 4 pula, from 5 to 10 does The normal loop.

grate

Eduardo
Trevisolli
Moderador
Moderador
Posts: 2016
Joined: Wed, 12 Jan 2005 3:25 pm
Location: Araraquara - SP
Abraço,

Trevisolli
OCA Oracle PL/SQL Developer Certified Associate
OCP Oracle Forms Developer Certified Professional
Araraquara-SP

Brother, beleza?

Would it be more or less?

Select all

 
-- Não listar 1 e 4 
BEGIN 
  FOR x IN 1..10 
  LOOP 
    IF x NOT IN (1,4) 
    THEN  
      dbms_output.put_line('Valor de x:'||x); 
    END IF; 
  END LOOP; 
END; 
If not, send us back, beleza?
User avatar
fsitja
Rank: OraSauro
Rank: OraSauro
Posts: 611
Joined: Mon, 19 Jan 2009 4:29 pm
Location: Gaúcho no Rio de Janeiro - RJ
"The scars exist to remind us that the past was real"
Campanha: Como fazer uma pergunta e obter uma resposta.
http://tkyte.blogspot.com/2005/06/how-t ... tions.html

OCA & OCP Developer — OCE SQL Expert — OCS Data Warehousing Specialist

The fetch will always be sequential, the fetch itself is not pulse, but processing within the loop.
From what I understand this is what Trevisolli said or your cursor query is bringing lines you should not and you have to fix in SQL, which gets much more intuitive and less with "workaround" face.
dudu0566
Rank: Analista Júnior
Rank: Analista Júnior
Posts: 74
Joined: Mon, 06 Aug 2007 3:59 pm
Location: Campinas - SP

Trevisolli and FSITJA

This Soluão meets my need.

But out of curiosity, there is no command that does this, like an abort, a next, or something like that ???

muito Thanks for everyone's attention.

Eduardo
Trevisolli
Moderador
Moderador
Posts: 2016
Joined: Wed, 12 Jan 2005 3:25 pm
Location: Araraquara - SP
Abraço,

Trevisolli
OCA Oracle PL/SQL Developer Certified Associate
OCP Oracle Forms Developer Certified Professional
Araraquara-SP

Brother,

From what I know, the only way out is you treat *** conditionally *** inside your loop.

If it is an explicit cursor, for example, you could work with% Rowcont and Tals.

Anything, send it there.
dudu0566
Rank: Analista Júnior
Rank: Analista Júnior
Posts: 74
Joined: Mon, 06 Aug 2007 3:59 pm
Location: Campinas - SP

Trevisolli,
Your tip has already killed the problem here !!!!

Regarding the Command is Curiosity ....

Thanks for the attention

Eduardo
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

It does not make sense to make a "Next" in a cursor.
Type: Comes line per line, then you test that line X you do not need. But at that moment the line has come ... You already have it, that is, you already did the fetch. Bear?

Then, the best way out is to put inside SQL not to bring what you do not need. Or if it is not possible to do this, put the IF as Trevisolli suggested.
papke
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Posts: 1
Joined: Fri, 19 Feb 2021 3:51 pm
Location: Canoas

Using continues to skip odd interacets

Select all

BEGIN 
  FOR n_index IN 1 .. 10 
  LOOP 
    -- skip odd numbers 
    IF MOD( n_index, 2 ) = 1 THEN 
      CONTINUE; 
    END IF; 
    DBMS_OUTPUT.PUT_LINE( n_index ); 
  END LOOP; 
END;
The output is:

Select all

2 
4 
6 
8 
10
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 19 guests