user1720827
user1720827

Reputation: 147

oralce apex_json to extract fields

Oracle 11g with Apex 5 is installed in my system. And I'm looking for the basic extraction of the field1 : total from the below json.

DECLARE 
    j apex_json.t_values; 
BEGIN 
    apex_json.parse(j, '{"total":83,"netAmmount":65}'); 
    DBMS_OUTPUT.put_line('Total   : ' ||
    APEX_JSON.get_number( 'total'));
    DBMS_OUTPUT.put_line('netAmmount: ' ||
    APEX_JSON.get_number( 'netAmmount'));
END;

Could you please let me know how to extract field1 and 2 using only oracle apex.

Upvotes: 0

Views: 513

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65323

In your case the JSON value has no array, therefore no need to use apex_json.t_values which can be replaced with a local variable of type varchar2 :

DECLARE 
    j    varchar2(32767) := '{"total":83,"netAmmount":65}'; 
BEGIN 
    APEX_JSON.parse( j ); 
    DBMS_OUTPUT.put_line('Total      : '||APEX_JSON.get_number( path => 'total' ) );
    DBMS_OUTPUT.put_line('Net Amount : '||APEX_JSON.get_number( path => 'netAmmount' ) );
END;
/

If the value of a field is a string, then replace APEX_JSON.get_number with APEX_JSON.get_varchar2 for that.

Upvotes: 1

Related Questions