37.13 GET_COUNT Function
This function returns the number of array elements or object members.
Syntax
APEX_JSON.GET_COUNT (
p_path IN VARCHAR2,
p0 IN VARCHAR2 DEFAULT NULL,
p1 IN VARCHAR2 DEFAULT NULL,
p2 IN VARCHAR2 DEFAULT NULL,
p3 IN VARCHAR2 DEFAULT NULL,
p4 IN VARCHAR2 DEFAULT NULL,
p_values IN t_values DEFAULT g_values )
RETURN NUMBER;
Parameters
Parameter | Description |
---|---|
p_path |
Index into p_values .
|
p[0-4] |
Each %N in p_path is replaced by pN and every i-th %s or %d is replaced by the p[i-1] .
|
p_values |
Parsed JSON members. The default is g_values .
|
Returns/Raised Errors
Return/Error | Description |
---|---|
NUMBER |
The number of array elements or object members or null if the array or object could not be found |
VALUE_ERROR |
Raises this error if p_values(p_path) is not an array or object.
|
Example
This example parses a JSON string and prints the number of members at positions.
DECLARE
j apex_json.t_values;
BEGIN
apex_json.parse(j, '{ "foo": 3, "bar": [1, 2, 3, 4] }');
dbms_output.put_line(apex_json.get_count(p_path=>'.',p_values=>j)); -- 2 (foo and bar)
dbms_output.put_line(apex_json.get_count(p_path=>'bar',p_values=>j)); -- 4
END;
Parent topic: APEX_JSON