37.20 GET_VALUE Function

This function returns the t_value.

Syntax

APEX_JSON.GET_VALUE (
    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 t_value;

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% or %d is replaced by the p[i-1].
p_values Parsed JSON members. The default is g_values.

Returns/Raised Errors

Return Description
t_value The t_value at the given path position. The record attributes are null if no data is 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 attributes of values at positions.

DECLARE
    j apex_json.t_values; 
    v apex_json.t_value; 
BEGIN 
    apex_json.parse(j, '{ "foo": 3, "bar": [1, 2, 3, 4] }'); 
    v := apex_json.get_value(p_path=>'bar[%d]',p0=> 2,p_values=>j); -- returns the t_value for bar[2] 
    dbms_output.put_line(v.number_value); -- 2 
    v := apex_json.get_value(p_path=>'does.not.exist',p_values=>j); 
    dbms_output.put_line(case when v.kind is null then 'not found!' end); 
END;