29.23 INITIALIZE_CLOB_OUTPUT Procedure

This procedure initializes the output interface to write to a temporary CLOB. The default is to write to SYS.HTP. If using CLOB output, call FREE_OUTPUT() at the end to free the CLOB.

Syntax

APEX_JSON.INITIALIZE_CLOB_OUTPUT (
    p_dur         IN PLS_INTEGER DEFAULT sys.dbms_lob.call,
    p_cache       IN BOOLEAN     DEFAULT TRUE,
    p_indent      IN PLS_INTEGER DEFAULT NULL,
    p_preserve    IN BOOLEAN     DEFAULT FALSE )

Parameters

Table 29-31 INITIALIZE_CLOB_OUTPUT Procedure Parameters

Parameter Description
p_dur Duration of the temporary CLOB. this can be DBMS_LOB.SESSION or DBMS_LOB.CALL (the default).
p_cache Specifies if the lob should be read into buffer cache or not.
p_indent Indent level. Defaults to 2 if debug is turned on, 0 otherwise.
p_preserve

Whether to preserve the currently active output object.

After calling FREE_OUTPUT, subsequent write calls will be executed on the preserved output. Defaults to FALSE.

If HTP output has already been initialized and a CLOB needs to be created, use p_preserve => true. After FREE_OUTPUT, subsequent output will be directed to the original HTP output again.

If p_preserve is true, you must call FREE_OUTPUT after JSON processing.

Example

This example configures APEX_JSON for CLOB output, generates JSON, prints the CLOB with DBMS_OUTPUT, and finally frees the CLOB.

BEGIN
  apex_json.initialize_clob_output( p_preserve => true );

  apex_json.open_object;
  apex_json.write('hello', 'world');
  apex_json.close_object;

  dbms_output.put_line(apex_json.get_clob_output);

  apex_json.free_output;
END;