Looping through block for each record [message #671377] |
Mon, 27 August 2018 04:42 |
|
RaShi.Raj
Messages: 84 Registered: May 2014 Location: Bangalore
|
Member |
|
|
Hi All,
I have a requirement to loop through all records in a block for each record from the same block. Something like below. Please help.
BEGIN
GO_BLOCK('BLOCK1');
FIRST_RECORD;
LOOP
GO_BLOCK('BLOCK1');
FIRST_RECORD;
LOOP
<business logic>
EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE'
NEXT_RECORD;
END LOOP;
EXIT WHEN:SYSTEM.LAST_RECORD = 'TRUE';
NEXT_RECORD;
END LOOP;
END;
Thanks,
Rashi
[Updated on: Mon, 27 August 2018 04:43] Report message to a moderator
|
|
|
|
|
|
Re: Looping through block for each record [message #671397 is a reply to message #671394] |
Tue, 28 August 2018 08:20 |
cookiemonster
Messages: 13958 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
You only need the first go_block - the others just seen you to the block you're in anyway (unless display_error_msg changes the block and I doubt that).
The v_dup variable is pointless - you're failing the whole process as soon as it's incremented to 1.
You can do this with a single pass over the block - build up an array of the relevant value(s) as you go then in each record check if the va;ue in the block already exists in the array - if it doesn't, add it, if it does raise an error. It'll be a lot more efficient that what you've got.
This check isn't going to stop users from saving duplicates, you'll need db constraints for that, so why not just rely on them?
|
|
|
|
|
|
|
|