Form中Block的重新查詢

來源:互聯網
上載者:User

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。

 

http://ema100.i.sohu.com/blog/view/203191409.htm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.