21.46 WRITE Procedure Signature 13
This procedure writes an attribute where the value is an array that contains all rows that the cursor returns. Each row is a separate object.
If the query contains object type, collection, or cursor columns, the procedure uses write(p_name,<xmltype>)
. See "WRITE Procedure Signature 14". Otherwise, it uses DBMS_SQL
to fetch rows and the write()
procedures for the appropriate column data types for output. If the column type is varchar2
and the uppercase value is 'TRUE'
or 'FALSE'
, it generates boolean values.
Syntax
APEX_JSON.WRITE (
p_name IN VARCHAR2,
p_cursor IN OUT NOCOPY sys_refcursor );
Parameters
Table 21-55 WRITE Procedure Parameters
Parameter | Description |
---|---|
p_name |
The attribute name. |
p_cursor |
The cursor. |
Example
This example writes an array containing JSON objects for departments 10 and 20, as an object member attribute.
DECLARE
c sys_refcursor;
BEGIN
open c for select deptno,
dname,
cursor(select empno,
ename
from emp e
where e.deptno=d.deptno) emps
from dept d;
apex_json.open_object;
apex_json. write('departments', c);
apex_json.close_object;
END;
{ "departments":[
{"DEPTNO":10,
"DNAME":"ACCOUNTING",
"EMPS":[{"EMPNO":7839,"ENAME":"KING"}]},
...
,{"DEPTNO":40,"DNAME":"OPERATIONS","EMPS":null}] }
Parent topic: APEX_JSON