15.33 OPEN_QUERY_CONTEXTファンクション

このファンクションは、ローカル・データベース、リモート・データベースまたはWebソース・モジュールの問合せコンテキストを開きます。

構文

function open_query_context(
    p_location               in apex_exec_api.t_location,
    --  
    p_table_owner            in varchar2                       default null,
    p_table_name             in varchar2                       default null,
    p_where_clause           in varchar2                       default null,
    p_order_by_clause        in varchar2                       default null,
    p_include_rowid_column   in boolean                        default false,
    --
    p_sql_query              in varchar2                       default null,
    p_plsql_function_body    in varchar2                       default null,
    p_optimizer_hint         in varchar2                       default null,
    --
    p_server_static_id       in varchar2                       default null,
    --
    p_module_static_id       in varchar2                       default null,
    p_web_src_parameters     in t_parameters                   default c_empty_parameters,
    p_external_filter_expr   in varchar2                       default null,
    p_external_order_by_expr in varchar2                       default null,
    --
    p_sql_parameters         in t_parameters                   default c_empty_parameters,
    p_auto_bind_items        in boolean                        default true,
    --
    p_columns                in t_columns                      default c_empty_columns,
    --
    p_filters                in t_filters                      default c_empty_filters,
    p_order_bys              in t_order_bys                    default c_empty_order_bys,
    --
    p_first_row              in pls_integer                    default null,
    p_max_rows               in pls_integer                    default null,
    --
    p_total_row_count        in boolean                        default false,
    p_total_row_count_limit  in number                         default null ) return t_context;

パラメータ

表15-31 OPEN_QUERY_CONTEXTファンクションのパラメータ

パラメータ 説明

p_location

問合せコンテキストを開く場所。ローカル・データベース、リモート・データベースまたはWebソース・モジュールのいずれかです。C_LOCATION_LOCAL_DBC_LOCATION_REMOTE_DBまたはC_LOCATION_WEB_SOURCE定数を使用します。

p_module_static_id

C_LOCATION_WEB_SOURCEp_location用に使用した場合、Webソース・モジュールの静的ID。

p_server_static_id

C_LOCATION_REMOTE_DBp_location用に使用した場合、リモート・サーバーの静的ID

p_table_owner

問合せタイプTABLEを使用する場合の表の所有者。

p_table_name

問合せタイプTABLEを使用する場合の表の名前。

p_where_clause

問合せタイプTABLEを使用する場合に追加するWHERE句。

p_order_by_clause

問合せタイプTABLEを使用する場合に追加するORDER BY句。

p_include_rowid_column

問合せタイプTABLEを使用する場合に、ROWID列をSELECTリストに追加します。デフォルトはfalseです。

p_sql_query

問合せタイプにSQL問合せを使用する場合に実行するSQL問合せ。

p_plsql_function_body

SQL問合せを戻すPL/SQLファンクションの本体。

p_optimizer_hint

APEXによって生成された最も外側のSQL問合せに適用されるオプティマイザ・ヒント。

p_external_filter_expr

Webソース・モジュールに渡される外部フィルタ式。

p_external_order_by_expr

Webソースに渡される外部ORDER BY式。

p_web_src_parameters

Webソース・モジュールに渡されるパラメータ。

p_auto_bind_items

APEXアイテム(ページおよびアプリケーション・アイテム)を自動的にバインドするかどうか。

p_sql_parameters

SQL問合せに使用する追加のバインド変数。

p_filters

問合せコンテキストに渡されるフィルタ。

p_order_bys

問合せコンテキストに渡されるORDER BY式。

p_columns

選択される列。

p_first_row

結果セットからフェッチする最初の行。

p_max_rows

フェッチする行の最大数。

p_total_row_count

総行数を求めるかどうか。

p_total_row_count_limit

総行数計算の上限値。

戻り値

問合せのカーソルを表すコンテキスト・オブジェクト。

次の例では、問合せを実行し、結果セットを出力します。このサンプル・コードは、PL/SQL実行リージョン内で使用できます。

declare
    l_context apex_exec.t_context; 
    --    
    l_idx_empno    pls_integer;
    l_idx_ename    pls_integer;
    l_idx_job      pls_integer;
    l_idx_hiredate pls_integer;
    l_idx_mgr      pls_integer;
    l_idx_sal      pls_integer;
    l_idx_comm     pls_integer;
    l_idx_deptno   pls_integer;
    --    
begin
    l_context := apex_exec.open_query_context(
        p_location          => apex_exec.c_location_local_db,
        p_sql_query         => 'select * from emp' );
    --   
    l_idx_empno    := apex_exec.get_column_position( l_context, 'EMPNO'); 
    l_idx_ename    := apex_exec.get_column_position( l_context, 'ENAME'); 
    l_idx_job      := apex_exec.get_column_position( l_context, 'JOB'); 
    l_idx_hiredate := apex_exec.get_column_position( l_context, 'HIREDATE'); 
    l_idx_mgr      := apex_exec.get_column_position( l_context, 'MGR'); 
    l_idx_sal      := apex_exec.get_column_position( l_context, 'SAL'); 
    l_idx_comm     := apex_exec.get_column_position( l_context, 'COMM'); 
    l_idx_deptno   := apex_exec.get_column_position( l_context, 'DEPTNO'); 
    --    
    while apex_exec.next_row( l_context ) loop
    --
        htp.p( 'EMPNO: ' || apex_exec.get_number  ( l_context, l_idx_empno    ) ); 
        htp.p( 'ENAME: ' || apex_exec.get_varchar2( l_context, l_idx_ename    ) );
        htp.p( 'MGR:   ' || apex_exec.get_number  ( l_context, l_idx_mgr      ) );
    --
    end loop;
    --        
    apex_exec.close( l_context );
    return;
exception
    when others then
        apex_exec.close( l_context );
        raise;    
end;