18.35 OPEN_QUERY_CONTEXT Function
This function opens a query context for a local database, remote database or a web source module.
Syntax
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;Parameters
Table 18-33 OPEN_QUERY_CONTEXT Function Parameters
| Parameter | Description | 
|---|---|
| 
 | Location to open the query context for. Can be local database , remote database or Web Source Module.                             Use Use the  | 
| 
 | Static ID of the Web Source Module, when  | 
| 
 | Static ID of the Remote Server, when  | 
| 
 | Table owner when query type  | 
| 
 | Table name when query type  | 
| 
 | Where clause to append when query type  | 
| 
 | Order by clause to append when query type  | 
| 
 | Add the  | 
| 
 | SQL Query to execute when query type SQL Query is used. | 
| 
 | PL/SQL function body returning SQL query. | 
| 
 | Optimizer hint to be applied to the most outer SQL query generated by APEX. | 
| 
 | External filter expression to be passed to a Web Source Module. | 
| 
 | External order by expression to be passed to a Web Source Module. | 
| 
 | Parameters to be passed to a web source module. | 
| 
 | Whether to auto-bind APEX items (page and application items). | 
| 
 | Additional bind variables to be used for the SQL query. | 
| 
 | Filters to be passed to the query context. | 
| 
 | Order by expressions to be passed to the query context. | 
| 
 | Columns to be selected . | 
| 
 | First row to be fetched from the result set. | 
| 
 | Maximum amount of rows to be fetched. | 
| 
 | Whether to determine the total row count. | 
| 
 | Upper boundary for total row count computation. | 
Returns
The context object representing a "cursor" for the query.
                  
Example
The following example executes a query and prints out the result set. This example code can be used within a Execute PL/SQLregion.
                  
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;Parent topic: APEX_EXEC