ファセット検索の結果をファンクションapex_region.open_query_contextにて取得できない、と相談がありました。
Oracle APEXではプロシージャapex_session.attachが提供されていて、セッションに紐づいているセッション・ステートやコレクションを異なるセッションから確認することができます。
以下のようにレポートのページがあったとします。
アプリケーションID
ページID
リージョンの静的ID
セッションID
です。
ページ・デザイナにてファセット検索が実装されているページを開き、アプリケーションID、ページID、リージョンの静的ID(未設定の場合は設定する)を取得します。
アプリケーションを実行し、URLよりセッションIDを取得します。
異なるセッションにアタッチするには、データベースに管理者で接続している必要があります。
Autonomous Databaseの場合は、管理ユーザーADMINにてデータベース・アクションに接続します。SQLの画面を開きます。
確認に使用するPL/SQLコードは以下になります。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare | |
l_app_id number; -- ファセット検索が実装されているアプリケーション | |
l_page_id number; -- ファセット検索が実装されているページ | |
l_session_id number; -- 実行中のアプリケーションのURLにsession=として現れるセッションID | |
l_region_static_id varchar2(80); -- ファセット検索のレポート・リージョンの静的ID | |
l_region_id number; -- 内部のリージョンID | |
l_context apex_exec.t_context; | |
begin | |
/* 以下、デバッグ対象の指定 */ | |
-- アプリケーションID、対象に応じて変更する。 | |
l_app_id := 108; | |
-- ページID、対象に応じて変更する。 | |
l_page_id := 1; | |
-- 実行中のアプリケーションに応じて変更する。 | |
l_session_id := 102255762743817; | |
-- レポートが実装されているリージョンの静的IDに変更する。 | |
l_region_static_id := 'CUSTOMERS'; | |
/* リージョンの内部IDを取得する */ | |
select region_id | |
into l_region_id | |
from apex_application_page_regions | |
where application_id = l_app_id | |
and page_id = l_page_id | |
and static_id = l_region_static_id; | |
dbms_output.put_line('Region ID for ' || l_region_static_id || ' is ' || l_region_id); | |
/* | |
* 実行中のアプリケーションのセッションにアタッチする。 | |
*/ | |
apex_session.attach( | |
p_app_id => l_app_id | |
, p_page_id => l_page_id | |
, p_session_id => l_session_id | |
); | |
/* | |
* 現在の検索条件で、レポートに設定されているSELECT文を実行する。 | |
*/ | |
l_context := apex_region.open_query_context( | |
p_page_id => l_page_id | |
, p_region_id => l_region_id | |
); | |
/* | |
* 検索結果を取得する。 | |
*/ | |
while apex_exec.next_row( l_context ) | |
loop | |
/* | |
* 3つめまでの列を取り出して印刷している。 | |
* 確認したいデータを特定する場合は、以下のように列名から列の位置を見つけて、 | |
* その位置を引数に指定する | |
* l_idx := apex_exec.get_column_position( l_context, 'EMAIL' ); | |
*/ | |
dbms_output.put_line(apex_exec.get_varchar2( l_context, 1)); | |
dbms_output.put_line(apex_exec.get_varchar2( l_context, 2)); | |
dbms_output.put_line(apex_exec.get_varchar2( l_context, 3)); | |
end loop; | |
apex_exec.close( l_context ); | |
-- detach | |
apex_session.detach; | |
end; |
データベース・アクションのSQLに貼り付けて実行すると、以下のように検索されている内容を確認できます。
今回の画面例では、デバッグの結果として以下が得られています。
Region ID for CUSTOMERS is 14378659533769063
3
田中一郎
ichiro@tanaka
1
山田花子
hanako@email
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.043
3
田中一郎
ichiro@tanaka
1
山田花子
hanako@email
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.043
このようなコードを実行することにより、ファセット検索の結果を別の端末より確認することができます。
完