【问题标题】:How to retain block position after a query -oracle forms查询-oracle表格后如何保留块位置
【发布时间】:2013-04-18 08:55:15
【问题描述】:

我有一个带有 data_block 的 oracle 表单,它显示 25 个项目。

在表单上,​​我有一个滚动条和一个“删除”按钮。当数据块中的一个项目被选中并按下“删除”按钮时,它会从数据库中删除选定的项目,然后执行 data_block 查询。

默认情况下,这会将用户返回到列表的顶部。

我正在尝试导航到从列表中删除的记录之前的记录。

这可以使用 GO_RECORD(number) 内置函数 (BIF) 来完成(假设 number 是 :System.cursor_record 的保存值)。

这就是我遇到问题的地方。 GO_RECORD BIF 会将记录带到显示的项目列表的顶部或底部。这会导致列表在没有警告的情况下上移 20 项。

即 例如,正在显示数据块中的记录 23 - 47,并选择记录 33。 如果删除了第 33 条记录,我们使用函数 GO_RECORD(32),那么显示的记录将是 32-56(有效地将列表向下移动 9 条记录)。

我假设为了避免这种转变,我需要有一些方法来确定记录在显示中的位置(而不是 data_block)。

有谁知道这个功能是否存在?

或者有没有人有其他方法可以让我得到相同的结果?

【问题讨论】:

    标签: oracle forms oracle10g oracleforms


    【解决方案1】:

    首先将此过程创建为程序单元

                PROCEDURE SYNC_BLOCK
                -----------------------------------------------------------------------*
                --  Synchronizes the display of any scrollable block.
                --  After running an edit that loops through all records, this will
                --  restore the block's display so that the same top record is again
                --  at the top of the block's display.
                --  Blk is the name of the block.
                --  Rec_Num is the desired target current record.
                --  Top_Rec is the original Top Record of the block captured
                --  before the looping process began.
                (BLK      VARCHAR2,
                REC_NUM  NUMBER,
                TOP_REC  NUMBER) IS
                BLK_ID    BLOCK;
                TOP_NEW   PLS_INTEGER;
                REC_N     PLS_INTEGER;
                --
                Procedure Check_success is begin
                If not form_success then
                Raise form_trigger_failure;
                End if;
                End Check_success;
                Procedure Go_Rec(rec_num number) is begin
                Go_Record(Rec_num);
                Check_Success;
                End Go_Rec;
                BEGIN
                BLK_ID := FIND_BLOCK(BLK);
                IF ID_NULL(BLK_ID) THEN
                Message('  U72_GO_REC_SYNC_BLOCK: CANNOT FIND BLOCK '''||BLK||'''');
                Raise Form_trigger_failure;
                END IF;
                IF BLK <> :SYSTEM.CURSOR_BLOCK THEN
                GO_BLOCK(BLK);
                Check_Success;
                END IF;
                IF :SYSTEM.CURSOR_RECORD <> REC_NUM THEN
                GO_REC(REC_NUM);
                END IF;
                -- may need to re-set the display to the rows originally shown
                TOP_NEW := GET_BLOCK_PROPERTY(BLK_ID, TOP_RECORD);
                IF TOP_REC <> TOP_NEW THEN
                IF TOP_REC < TOP_NEW THEN
                IF :SYSTEM.CURSOR_RECORD <> TOP_REC THEN
                GO_REC(TOP_REC);
                END IF;
                ELSE
                REC_N := GET_BLOCK_PROPERTY(BLK_ID, RECORDS_DISPLAYED)
                + TOP_REC - 1;
                IF :SYSTEM.CURSOR_RECORD <> REC_N THEN
                GO_REC(REC_N);
                END IF;
                END IF;
                SYNCHRONIZE;
                -- Found that Sync caused focus change to different block. Fix here.
                IF BLK <> :SYSTEM.CURSOR_BLOCK THEN
                GO_BLOCK(BLK);
                Check_Success;
                END IF;
                IF :SYSTEM.CURSOR_RECORD <> REC_NUM THEN
                GO_REC(REC_NUM);
                END IF;
                END IF;
                -- can't go_rec to NEW record, so need to test here
                IF  :SYSTEM.LAST_RECORD = 'TRUE'
                AND REC_NUM = 1 + :SYSTEM.CURSOR_RECORD THEN
                NEXT_RECORD;
                Check_Success;
                END IF;
                --
                END SYNC_BLOCK;
    

    下面这五行代码完全符合您的要求

    xx:=GET_BLOCK_PROPERTY('blk',TOP_RECORD);
    xxx:=GET_BLOCK_PROPERTY('blk',CURRENT_RECORD );
    go_block('blk');
    execute_query();
    SYNC_BLOCK('blk',xxx,xx);
    

    如果您需要更多信息,请随时与我联系

    【讨论】:

      【解决方案2】:

      -- 保存最高记录

       l_top_rec:= GET_BLOCK_PROPERTY('EXP_DETAIL_BLK', TOP_RECORD);
       l_cur_rec:= :SYSTEM.CURSOR_RECORD;
      

      -- 你的行动

       execute_query; // or othres actions...
      

      -- 创下最高纪录

      go_block(block_name);
      --
      first_record;
      loop
        exit when GET_BLOCK_PROPERTY(block_name, TOP_RECORD) = l_top_rec;
        next_record;
      end loop;
      go_record(l_top_rec);
      --
      loop
        exit when :SYSTEM.CURSOR_RECORD = l_cur_rec or :SYSTEM.LAST_RECORD = 'TRUE';
        next_record;
      end loop; 
      

      【讨论】:

        猜你喜欢
        • 2021-04-03
        • 1970-01-01
        • 2013-08-23
        • 1970-01-01
        • 1970-01-01
        • 2021-01-24
        • 2012-03-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多