Search code examples
oracle-databaseplsqlplsqldeveloper

How to modify a value of a json array from a value but not from a key (Oracle, PL SQL)?


  • I want to change my value '4444' to '7727'
  • knowing that I only have the old value ('4444') and the new value ('7727') but not the key
["4444","5555"]

after modification

["7727","5555"]

Solution

  • Here is a function I made to modify a value of a json array from a value not from a key (old value = '4444', new value = '7727')

    nmr_cmpt_json := JSON_ARRAY_T.parse(nmrs_cmpts_tab);
    i := 0;
        loop
            exit when i> nmr_cmpt_json.get_Size ;
            if nmr_cmpt_json.get_String(i) = '4444' then
                nmr_cmpt_json.put(i, '7727', TRUE);
                nmrs_cmpts_tab:= nmr_cmpt_json .to_string;
                dbms_output.put_line( 'nmr_cmpt_json = ' || nmr_cmpt_json.stringify);
                exit;    
            end if;
            i := i +1;
        end loop;