29.58 WRITE_CONTEXT Procedure

This procedure writes an array with all rows that the context handle returns. Each row is a separate object.

If the query contains object type, collection or cursor columns, an error is raised. If the column is VARCHAR2 and the uppercase value is 'TRUE' or 'FALSE', boolean values are generated.

Syntax

PROCEDURE WRITE_CONTEXT (
   p_name        IN VARCHAR2
   p_context     IN apex_exec.t_context,
   p_write_null  IN BOOLEAN  DEFAULT FALSE );

Parameters

Table 29-72 WRITE_CONTEXT Procedure Parameters

Parameter Description

p_name

The attribute name.

p_context

The context handle from an APEX_EXEC.OPEN_QUERY_CONTEXT call.

p_write_null

Whether to write (true) or omit (false) null values.

Example

This example opens an APEX_EXEC quey context selecting the DEPT table and passes it to APEX_JSON.

DECLARE
    l_context apex_exec.t_context;
begin
    l_context := apex_exec.open_query_context( 
                     p_location   => apex_exec.c_location_local_db,
                     p_sql_query  => q'#select * from dept#' );

   apex_json.open_object;
   apex_json.write_context( p_name => 'departments', p_context => l_context);
   apex_json.close_object;
 end;

{ "departments":[
     { "DEPTNO":10 ,"DNAME":"ACCOUNTING" ,"LOC":"NEW YORK" }
    ,{ "DEPTNO":20 ,"DNAME":"RESEARCH" ,"LOC":"DALLAS" } 
    ,{ "DEPTNO":30 ,"DNAME":"SALES" ,"LOC":"CHICAGO" } 
    ,{ "DEPTNO":40 ,"DNAME":"OPERATIONS" ,"LOC":"BOSTON" } ] }