You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle Forms 10g多行复制至另一块代码死循环问题求助

Hey there! Let's dig into why your Oracle Forms code is stuck in an infinite loop and fix it up for you.

What's Causing the Loop?

Your original code has a few key issues that lead to the endless cycle:

  1. Syntax Error: The line l_job := :first.job is missing a trailing semicolon. This breaks compilation and can trigger unexpected runtime behavior, including loops that don't terminate.
  2. Unreliable Record Traversal: Using an incrementing counter (l_currec) to jump between records is risky. When the counter exceeds the actual number of records in the first block, Oracle Forms won't jump to a non-existent record—it'll just stay on the last one. This means your code will keep copying the final record to the second block forever.
  3. Timing of Exit Logic: The exit check happens after copying the record, but the counter keeps increasing even when you're already on the last record, leading to repeated, unnecessary iterations.

Fixed Code

Here's a revised version that safely traverses records and avoids the loop:

DECLARE
    -- Declare variables matching the fields you want to copy
    l_empno emp.empno%TYPE;
    l_ename emp.ename%TYPE;
    l_job   emp.job%TYPE;
BEGIN
    -- Navigate to the source block and start at the first record
    GO_BLOCK('first');
    FIRST_RECORD;

    LOOP
        -- Save values from the current source record
        l_empno := :first.empno;
        l_ename := :first.ename;
        l_job   := :first.job; -- Fixed the missing semicolon here

        -- Move to the target block, go to the end, and create a new record
        GO_BLOCK('second');
        LAST_RECORD;
        CREATE_RECORD;

        -- Populate the new target record with saved values
        :second.empno := l_empno;
        :second.ename := l_ename;
        :second.job   := l_job;

        -- Exit the loop if we just processed the last source record
        EXIT WHEN :system.last_record = 'TRUE';

        -- Move to the next record in the source block
        GO_BLOCK('first');
        NEXT_RECORD;
    END LOOP;
END;

Key Improvements

  • Safe Record Traversal: Using FIRST_RECORD and NEXT_RECORD ensures we only move through existing records in the source block—no more stuck-on-last-record issues.
  • Fixed Syntax: Added the missing semicolon to ensure the code compiles and runs as expected.
  • Clean Exit Logic: We check if we're on the last source record right after copying, so the loop terminates immediately after processing the final row.

Quick Extra Tips

  • If your source block might be empty, add a check upfront: IF :system.record_count = 0 THEN RETURN; END IF; to skip the loop entirely.
  • If you need to clear existing records in the target block before copying, add CLEAR_BLOCK(NO_VALIDATE); right after GO_BLOCK('second'); (adjust the validation flag based on your needs).

内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:30:55