form里面APP_RECORD.FOR_ALL_RECORDS这个命令,可以遍历block中的每一项,准确的说会在块级触发器触发的时候,调用项中对应触发器的程序,实现block中所有行的项的触发功能。
比如实现check_box的全选、重新计算表中的行号,批量修改界面行状态等功能。
Renumbering All Records in a Window
To renumber an item sequentially for all records on the block, create a user-named trigger to increment the sequence variable and set the sequence item. Use the procedure APP_RECORD.FOR_ALL_ RECORDS to fire the trigger once for each record. To number an item sequentially as records are created, create a variable or item to contain the sequence number. Create a WHEN-CREATE- RECORD trigger to increment the sequence variable and default the sequence item. However, if you want to renumber all the records in a window, use the procedure APP_RECORD.FOR_ALL_RECORDS. If you are renumbering your items after a query or commit, you may wish to reset the record status so that the record is not marked as changed.
developer User Guide中的说明
Example
A block lines has item line_number. When a record is deleted, line_number must be renumbered.
1. Create your item handler procedures as follows:
PACKAGE BODY lines IS
line_number_seq number := 0;
PROCEDURE delete_row IS
BEGIN
line_number_seq := 0;
APP_RECORD.FOR_ALL_RECORDS('reseq_line_number');
END delete_row;
END lines;
2. Create a user-defined trigger RESEQ_LINE_NUMBER as follows:
lines.line_number_seq := lines.line_number_seq + 1;
:lines.line_number := lines.line_number_seq;
3. Call your item handler procedures in:
Trigger: KEY-DELETE:
lines.line_number('KEY-DELETE');
Warning:
Be aware of the consequences of this type of processing. Specifically, consider the following points:
If a very large number of records are queried in a block, looping through them one at a time can be very slow.
Not all the records that could be in the block may be in the current query set if you allow the user to enter the query.
If you are changing a value that is part of a unique key, you may get errors at commit time because the record currently being committed may conflict with another already in the database, even though that record has also been changed in the block.
FORM BUILDER的全选例子:
添加一个CHECKBOX完成全选功能,红框为新添加的CHECKBOX(如图示)
Try to use APP_RECORD.FOR_ALL_RECORDS
ex:Soure Block:TEST Soure Item:CHECK(is a Checkbox Item)
1、BLOCK:CONTROL(Non Database Data Block) Add a Checkbox Item(Item Name:ALL_CHECK)
2、CONTROL.ALL_CHECK add Trigger(Item Level) -- WHEN-CHECKBOXBOX-CHANGED
---------------------------------------------------------------------------
BEGIN
APP_RECORD.FOR_ALL_RECORDS ('TEST' --Source Block
,'ALL_CHECK' --Source Block Trigger
);
END;
---------------------------------------------------------------------------
3、Block:TEST add User-define Trigger(Block Level), Trigger Name:ALL_CHECK
---------------------------------------------------------------------------
BEGIN
IF :CONTROL.ALL_CHECK = 'Y' THEN
:TEST.CHECK = 'Y';
ELSE
:TEST.CHECK = 'N';
END IF;
END;