21.41 WRITE Procedure Signature 8

This procedure writes an object attribute of type VARCHAR2.

Syntax

APEX_JSON.WRITE (
    p_name        IN VARCHAR2,
    p_value       IN VARCHAR2,
    p_write_null  IN BOOLEAN  DEFAULT FALSE );

Parameters

Table 21-50 WRITE Procedure Parameters

Parameter Description

p_name

The attribute name.

p_value

The attribute value to be written.

p_write_null

If true, write NULL values. If false (the default), do not write NULLs.

Example

This example writes an object with named member attributes of various types. The comments to the right of the statements show the output that they generate.

DECLARE
  l_clob clob := 'long text';
  l_xml sys.xmltype := sys.xmltype('<obj><foo>1</foo><bar>2</bar></obj>');
BEGIN
  apex_json.open_object; -- {
  apex_json.write('a1', 1); -- "a1": 1
  apex_json.write('a2', 'two'); -- ,"a2": "two"
  apex_json.write('a3', l_clob); -- ,"a3": "long text"
  apex_json.write('a4', false); -- ,"a4": false
  apex_json.write('a5', sysdate); -- ,"a5": "2014-05-05T05:36:08Z"
  apex_json.write('a6', l_xml); -- ,"a6": { "foo": 1, "bar": 2 }
  apex_json.close_object; -- }
END;