Question

I'm new to Oracle Form and pl/sql. Here is my problem In my form, I got 3 data blocks that display records that I retrieve from a table named BOS_M_HOLIDAY. But somehow only the last record displayed in each datablocks after the loop. The way I retrieve the records is using the PRE-FORM Trigger and WHEN-TIME-EXPIRED Trigger. Here is my code in PRE-FORM Trigger:

DECLARE

CURSOR a_aa is SELECT HOL_DATE FROM BOS_M_HOLIDAY WHERE REGEXP_LIKE(HOL_DATE, '.......12') ORDER BY HOL_DATE;
CURSOR a_bb is SELECT HOL_DATE FROM BOS_M_HOLIDAY WHERE REGEXP_LIKE(HOL_DATE, '.......13') ORDER BY HOL_DATE ;
CURSOR a_cc is SELECT distinct DESCR FROM BOS_M_HOLIDAY WHERE REGEXP_LIKE(HOL_DATE, '.......13')ORDER BY 1;
Timer_ID TIMER;

BEGIN

OPEN a_aa;
LOOP
    FETCH a_aa INTO :holiday_2012.HOL_DATE;
    EXIT WHEN a_aa%notfound;
    Timer_ID := FIND_TIMER('CALL_NEXT_RECORD');
        IF NOT Id_Null(Timer_ID) THEN
        Delete_Timer(Timer_ID);
        END IF;
    Timer_ID := Create_Timer('CALL_NEXT_RECORD',1,NO_REPEAT);
END LOOP;
CLOSE a_aa;

OPEN a_bb;
LOOP
    FETCH a_bb INTO :holiday_2013.HOL_DATE;
    EXIT WHEN a_bb%notfound;
    Timer_ID := FIND_TIMER('CALL_NEXT_RECORD');
        IF NOT Id_Null(Timer_ID) THEN
        Delete_Timer(Timer_ID);
        END IF;
    Timer_ID := Create_Timer('CALL_NEXT_RECORD',1,NO_REPEAT);
END LOOP;
CLOSE a_bb;

OPEN a_cc;
LOOP
    FETCH a_cc INTO :description.DESCR;
    EXIT WHEN a_cc%notfound;
    Timer_ID := FIND_TIMER('CALL_NEXT_RECORD');
        IF NOT Id_Null(Timer_ID) THEN
        Delete_Timer(Timer_ID);
        END IF;
    Timer_ID := Create_Timer('CALL_NEXT_RECORD',1,NO_REPEAT);
END LOOP;
CLOSE a_cc;

END;

and here is my code in WHEN-TIME-EXPIRED Trigger:

DECLARE
v_Timer VARCHAR2(30) := Get_Application_Property(TIMER_NAME);
BEGIN
IF (v_Timer = 'CALL_NEXT_RECORD') THEN
    NEXT_RECORD;
END IF;
END;

This code works when I use WHEN-BUTTON-PRESSED Trigger without the TIMER part. Bare with my English and feel free to ask me if any parts that you do not understand. Thanks!

Was it helpful?

Solution

In your loops, each record is being assigned to the same (1st) record in each block. Sure, you create a timer which issues a NEXT_RECORD, but this is by far the worst possible idea - and doesn't work anyway because by the time the timer actually executes, most (if not all) of your loops have already finished. There's nothing in your loop that waits for the timer to finish before it goes onto the next record - in fact, it probably creates and destroys the timer many times before the timer ever gets a chance to actually run!

Don't use timers for this sort of thing. You need to call NEXT_RECORD within your loop.

Also, I'd recommend you don't put this sort of code in PRE-FORM - instead, put it in your WHEN-NEW-FORM-INSTANCE trigger.

Even better, you should base the blocks on the table (put the predicate in the DEFAULT_WHERE property) and execute the query, instead of using this procedural code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top