Oracle Apex:为可编辑交互式网格创建主地址自动设置流程
Auto-Set "Main Address" in Interactive Grid for First New Row
Hey there, let's get this Interactive Grid (IG) auto-setup working exactly how you need it. I've built similar logic for APEX apps before, so here's a step-by-step breakdown to make it smooth:
Step 1: Create a Before Submit PL/SQL Process
We need our logic to run before the default IG insert process kicks in. Here's how to set it up:
- Head to your page's Processing tab.
- Click Add Process > Select PL/SQL Process.
- Name it something clear, like
Auto-Set Main Address for New Rows. - Set the Process Point to Before Submit.
- For the trigger condition, make sure it only runs when the IG saves changes:
- Condition Type:
Request = Expression 1 - Expression 1:
'IG$YOUR_IG_STATIC_ID$SAVE'(replaceYOUR_IG_STATIC_IDwith your IG's actual static ID—you can find this in the IG's properties under the Advanced tab)
- Condition Type:
Step 2: Add the Logic to Set Main Address
Paste this PL/SQL code into the process (adjust table/column names to match your schema):
DECLARE l_existing_addresses NUMBER; -- Replace :P1_PARENT_RECORD_ID with your page item holding the parent record ID (e.g., customer ID) l_parent_id NUMBER := :P1_PARENT_RECORD_ID; BEGIN -- Count how many addresses already exist for the parent record SELECT COUNT(*) INTO l_existing_addresses FROM YOUR_ADDRESSES_TABLE -- Replace with your actual table name WHERE PARENT_FOREIGN_KEY = l_parent_id; -- Replace with your foreign key column -- Set Main Address based on existing count IF l_existing_addresses = 0 THEN -- First ever address: auto-set to Yes :APEX$ROW_MAIN_ADDRESS := '1 - Yes'; -- Column name must match your IG's column (uppercase, prefixed with APEX$ROW_) ELSE -- Subsequent addresses: auto-set to No :APEX$ROW_MAIN_ADDRESS := '0 - No'; END IF; END;
Step 3: Adjust Process Order & Column Settings
- Drag your new process above the default IG save processes (like
IG$YOUR_IG_STATIC_ID - Save Interactive Grid Data) to ensure it runs first. - Optional: If you don't want users to manually override the Main Address value, go to your IG's Columns tab, select the
MAIN ADDRESScolumn, and set Editable toNo.
Step 4: Test It Out
- Navigate to your page when there are no existing addresses for the parent record.
- Add a new row in the IG and save—you'll see
1 - Yesautomatically set for Main Address. - Add another row and save—this one will auto-set to
0 - No.
That's all! This logic handles the auto-setting while letting the default IG flow take care of the actual table insert.
内容的提问来源于stack exchange,提问作者Yuri Ivanoff
相关产品推荐
相关产品推荐

