如何在查询后保留块位置 -oracle 形式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16198217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to retain block position after a query -oracle forms
提问by Rolan
I have an oracle form with a data_block which displays 25 items.
我有一个带有 data_block 的 oracle 表单,它显示 25 个项目。
On the form I have a scrollbar and a 'delete' button. When an item in the data block is selected, and the 'delete' button is pressed, it deletes the selected item from the database and then executes the data_block query.
在表单上,我有一个滚动条和一个“删除”按钮。当数据块中的一项被选中,并按下“删除”按钮时,它会从数据库中删除选中的项,然后执行 data_block 查询。
By default, this returns the user to the top of the list.
默认情况下,这会将用户返回到列表的顶部。
I am trying to navigate to the record just before the one that is deleted from the list.
我正在尝试导航到从列表中删除的记录之前的记录。
This can be done using the GO_RECORD(number) Built in Function(BIF) (assuming number is the saved value of :System.cursor_record).
这可以使用 GO_RECORD(number) 内置函数 (BIF) 来完成(假设 number 是 :System.cursor_record 的保存值)。
And this is where I run into a problem. The GO_RECORD BIF will bring the record to the top or bottom of the displayed list of items. This can cause the list to shift up 20 items without warning.
这就是我遇到问题的地方。GO_RECORD BIF 会将记录带到显示的项目列表的顶部或底部。这可能会导致列表在没有警告的情况下上移 20 个项目。
i.e. For example Records 23 - 47 from the data_block are being displayed, and record 33 is selected. If record 33 is deleted and we use the function GO_RECORD(32), then the records diplayed will be 32-56 (effectively shifting the list down 9 records).
即例如,正在显示来自 data_block 的记录 23 - 47,并选择了记录 33。如果删除记录 33 并使用函数 GO_RECORD(32),则显示的记录将为 32-56(有效地将列表向下移动 9 条记录)。
I'm assuming that in order to avoid this shift I will need to have some way of detemining the position of the record in the display (as opposed to the data_block).
我假设为了避免这种转变,我需要某种方式来确定显示中记录的位置(与 data_block 相对)。
Does anyone know if this functionality exists?
有谁知道这个功能是否存在?
Or does anyone have another approach that might get me the same result?
或者有人有另一种方法可以让我得到相同的结果吗?
回答by Ali Gaaly
first create this procedure as a program unit
首先将此过程创建为程序单元
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;
second this below five lines of code do exact what you want
其次这下面的五行代码做你想要的
xx:=GET_BLOCK_PROPERTY('blk',TOP_RECORD);
xxx:=GET_BLOCK_PROPERTY('blk',CURRENT_RECORD );
go_block('blk');
execute_query();
SYNC_BLOCK('blk',xxx,xx);
please do not hesitate to contact me if you require further information
如果您需要更多信息,请随时与我联系
回答by ROD
-- save top record
-- 保存最高记录
l_top_rec:= GET_BLOCK_PROPERTY('EXP_DETAIL_BLK', TOP_RECORD);
l_cur_rec:= :SYSTEM.CURSOR_RECORD;
-- your actions
——你的行动
execute_query; // or othres actions...
-- set top record
——创下最高纪录
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;