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.
loop to look for lines with repeated numbers
- dr_gori
- 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
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:
(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
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:
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;
: -O
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
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
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
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;
- tiago_pimenta
- Rank: DBA Júnior
- Posts: 213
- Joined: Wed, 29 Jun 2011 9:49 am
- Location: Barretos / SP
select distinct(campo) from tabela
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.
- tiago_pimenta
- 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.
- dr_gori
- 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
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.
(ie scroll through the block and go inserting, since it is not base-table).
Dai is easy to find duplicates.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 11 guests