[转]Form中Block的重新查询后定位到原位置

Form中某些按钮可能调用了Package对表中某些字段进行更新,但是数据库中字段的修改不会马上反映到form的界面上,所以要进行重新查询,但是用户可能使用了查询窗口进行查询之后然后再点击按钮动作,如果简单的使用execute_query进行查询的话那么就会把原来的查询条件冲掉。所以这里写了一个公用的包进行查询:


procedure query_block(p_block_name varchar2)
is
l_cursor_block varchar2(50);
l_cursor_record number;
l_cursor_item varchar2(50);
l_trigger_record number;
l_default_where varchar2(1000);
l_last_query varchar2(2000);
l_where_anchor number;
l_order_anchor number;
l_where_clause varchar2(1000);
l_message_level number;

begin
l_cursor_item := name_in(‘SYSTEM.CURSOR_ITEM’);
l_cursor_record := name_in(‘SYSTEM.CURSOR_RECORD’);
l_cursor_block := name_in(‘SYSTEM.CURSOR_BLOCK’);
l_trigger_record := l_cursor_record;
l_message_level := :system.message_level;
if l_cursor_block <> p_block_name then
l_trigger_record := get_block_property(p_block_name, CURRENT_RECORD);
go_block(p_block_name);
if name_in(‘SYSTEM.CURSOR_BLOCK’) <> p_block_name then
fnd_message.debug(‘DEVELOPER ERROR: To select records ‘||
‘in another block, you must be able to navigate.’);
raise FORM_TRIGGER_FAILURE;
end if;
end if;
l_default_where := get_block_property(p_block_name, DEFAULT_WHERE);
l_last_query := get_block_property(p_block_name, LAST_QUERY);
//检查是否有Order By语句
if instr(upper(l_last_query), ‘ORDER BY’) = 0 then
l_order_anchor := length(l_last_query);
else
l_order_anchor := instr(upper(l_last_query), ‘ORDER BY’) – 1;
end if;

if instr(upper(l_last_query), ‘WHERE’) = 0 then
l_where_anchor := l_order_anchor – 5;
else
l_where_anchor := instr(upper(l_last_query), ‘WHERE’) + 1;
end if;
l_where_clause := substr(l_last_query, l_where_anchor+5, l_order_anchor-l_where_anchor-4);

set_block_property(p_block_name,default_where,l_where_clause);
:system.message_level := 25;
execute_query;
:system.message_level := l_message_level;
set_block_property(p_block_name,default_where,l_default_where);
go_block(p_block_name);
go_record(l_trigger_record);

go_block(l_cursor_block);
go_record(l_cursor_record);
go_item(l_cursor_item);

end query_block;

程序首先保存当前的block,record以及Item使得在执行完之后光标依然停留在原位置而不会跳来挑去。之后判断当前所在的Block是否和参数传进来的P_Block一致,如果不一致,那么就go到P_Block上,然后获取该Block的Last_Query,由于可能查询带有Order By,所以需要判断是否带有Order By来决定截取的最终位置。取得了where条件之后,通过使用set_block_property(p_block_name,default_where,l_where_clause)以及execute_query对block进行查询,在这之前需要先保存原来的default where,在查询之后将default_where设置为默认的。最后讲光标定位到原位置。

调用的时候输入Block Name,便可以截取到Block的查询条件查询该Block。


http://oracleseeker.com/2008/09/10/data-block-is-queryed-again-in-form/

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24627116/viewspace-774615/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24627116/viewspace-774615/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值