PROCEDURE display_table (table_in IN , end_row_in IN INTEGER , start_row_in IN INTEGER := 1, failure_threshold_in IN INTEGER := 0, increment_in IN INTEGER := +1) IS /* The current row displayed as I scan through the table */ current_row INTEGER := start_row_in; /* || Keeps track of number of misses, which will be compared || to the failure threshold parameter. The Boolean variable || is used to halt the scan through the table. */ count_misses INTEGER := 0; within_threshold BOOLEAN := TRUE; /*----------------------- Local Module ------------------------*/ || Determine if specified row is within range. I put this || into a function because I need to see which direction I || am scanning in order to determine whether I'm in range. */ FUNCTION in_range (row_in IN INTEGER) RETURN BOOLEAN IS BEGIN IF increment_in < 0 THEN RETURN row_in >= end_row_in; ELSE RETURN row_in <= end_row_in; END IF; END; BEGIN /* The increment cannot be zero! */ IF increment_in = 0 THEN DBMS_OUTPUT.PUT_LINE ('Increment for table display must be non-zero!'); ELSE /* || Since I allow the user to pass in the amount of the increment || I will switch to a WHILE loop from the FOR loop. I keep || scanning if (1) have not reached last row and (2) if I have || not run into more undefined rows than allowed by the || threshold parameter. */ WHILE in_range (current_row) AND within_threshold LOOP /* || I place the call to PUT_LINE within its own anonymous block. || This way I can trap a NO_DATA_FOUND exception and keep on || going (if desired) without interrupting the scan. */ BEGIN /* Display the message, including the row number */ DBMS_OUTPUT.PUT_LINE ('Value in row ' || TO_CHAR (current_row) || ': ' || table_in (current_row)); /* Increment the counter as specified by the parameter */ current_row := current_row + increment_in; EXCEPTION WHEN NO_DATA_FOUND THEN /* || If at the threshold then shut down the WHILE loop by || setting the Boolean variable to FALSE. Otherwise, || increment the number of misses and current row. */ within_threshold := count_misses < failure_threshold_in; IF within_threshold THEN count_misses := count_misses + 1; current_row := current_row + increment_in; END IF; END; END LOOP; /* || If I stopped scanning because of undefined rows, let the || user know. */ IF NOT within_threshold THEN DBMS_OUTPUT.PUT_LINE ('Exceeded threshold on undefined rows in table.'); END IF; END IF; END;