loop to look for lines with repeated numbers

Dicas do Oracle Forms Builder - Blocos, Itens, LOV, Canvas, Triggers, comandos, PLL, d2kwutil, FMB, Alert, menus, etc
Post Reply
dcp
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 17
Joined: Tue, 17 Sep 2013 11:02 am

I have a tabular block with 4 items on the same table, I want to sweep this block and check if the number 1 was typed, if not, give a msg to the user that the code was not informed and out of the loop.
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

If the block is base table, simply run the POST command and do a same query.
The "post" sends all data that are in the blocks to the database, but without doing Commit. This way you can do query normally.

If the block is not base-table, then it will have to make a loop.
Something like this:

Select all

 
DECLARE 
  v_encontrou BOOLEAN := FALSE; 
BEGIN 
 
  GO_BLOCK('seubloco'); 
  FIRST_RECORD; 
  LOOP 
    IF :seubloco.seucampo = 'algoQueVoceQuerTestar'  
    THEN  
      v_encontrou := TRUE; 
      EXIT; 
    END IF; 
 
    IF :SYSTEM.LAST_RECORD = 'TRUE' 
    THEN EXIT; 
    ELSE NEXT_RECORD; 
    END IF; 
  END LOOP; 
 
  --se não encontrou, coloca o codigo que você quer aqui. 
  IF not V_ENCONTROU 
  THEN 
     --ERROR MESSAGE 
     -- ETC 
     NULL; 
     RETURN; 
  END IF; 
 
  --se encontrou, coloca o codigo aqui do sucesso. 
  COMMIT; 
 
END;  
(I have not tested this, to no oracle here: Oops: ... but it is there). Remembering that this does not test if you have repeated numbers, according to the title of the post. It only tests if a number exists in the block, according to what was explained in the message)
: -O
dcp
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 17
Joined: Tue, 17 Sep 2013 11:02 am

is the title is wrong even hahaa: mrgreen:
I can make this code on a button when-button-pressed também right?
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

Yes, quiet.
dcp
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 17
Joined: Tue, 17 Sep 2013 11:02 am

It cost !!
I made some modifications and applied perfectly, but the way is this ...

I have one more doubt. :?:

Using the same condition below but ... When I find a repeated code, rather than I return the boolean false variable I only show that code.
Ex:
COD
1
2
1
3
----
Result
1
2
3
I thought of something like

Select all

 
DECLARE 
  v_encontrou BOOLEAN := FALSE; 
  v_id        number := :seubloco.seucampo; 
BEGIN 
 
  GO_BLOCK('seubloco'); 
  FIRST_RECORD; 
  LOOP 
    IF :seubloco.seucampo <> v_id THEN  
      v_encontrou := FALSE; 
      EXIT; 
    END IF; 
 
    IF :SYSTEM.LAST_RECORD = 'TRUE' 
    THEN EXIT; 
    ELSE NEXT_RECORD; 
    END IF; 
  END LOOP; 
 
  --se não encontrou, coloca o codigo que você quer aqui. 
  IF not V_ENCONTROU THEN 
     mas(v_id); 
  
  END IF;   
 	 
  --se encontrou, coloca o codigo aqui do sucesso. 
   
  COMMIT; 
   
END; 
would have to show within the Msg All fields that do not repeat more than 1 time, repeat more than 1 time show only the first occurrence, discarding the second. : Shock :: P
User avatar
tiago_pimenta
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 213
Joined: Wed, 29 Jun 2011 9:49 am
Location: Barretos / SP

Select all

select distinct(campo) from tabela
This will show all codes one time without repeating when you have repeated.
dcp
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 17
Joined: Tue, 17 Sep 2013 11:02 am

I do not know if using the above structure would give to do with DML commands. In this case I will not give Commit at the end, when this loop sweeping the block would have to show all records without duplicity, even if I should not show.
User avatar
tiago_pimenta
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 213
Joined: Wed, 29 Jun 2011 9:49 am
Location: Barretos / SP

Well, if the situation is a non-base-table block, then you will have to use two loop's, a walking the block and another traversing the array where the values ??you will show, then just use logic, if already Exist in array you do not add, if you do not exist, add.
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

If it is many rows, it may be worth inserting these values ??into a temporary table.
(ie scroll through the block and go inserting, since it is not base-table).

Dai is easy to find duplicates.
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests