zoukankan      html  css  js  c++  java
  • 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+6, l_order_anchor-l_where_anchor-5);       
     

      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。

  • 相关阅读:
    hdu 1199 Color the Ball 离散线段树
    poj 2623 Sequence Median 堆的灵活运用
    hdu 2251 Dungeon Master bfs
    HDU 1166 敌兵布阵 线段树
    UVALive 4426 Blast the Enemy! 计算几何求重心
    UVALive 4425 Another Brick in the Wall 暴力
    UVALive 4423 String LD 暴力
    UVALive 4872 Underground Cables 最小生成树
    UVALive 4870 Roller Coaster 01背包
    UVALive 4869 Profits DP
  • 原文地址:https://www.cnblogs.com/liuweicong39/p/2530595.html
Copyright © 2011-2022 走看看