Code change for supporting empty arrays

  • Jose Canciani

    Jose Canciani - 2009-05-21

    Hello Lewis.

    I'm using your code to generate JSON objects, it works great! I've found that if you try to add an array object without any members, you get a:

    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at "JOSE.JSON", line 225

    This is because in line 225 of json_body.typ you are looping like this:
        FOR j IN 1..v_json_element_array.LAST

    Since v_json_element_array is not defined, you have a numeric or value error there.

    I've modified the script to add an if check before looping:

    LINE 225: IF v_json_element_array.COUNT > 0 THEN FOR j IN 1..v_json_element_array.LAST


    Now the array in the json text shows up like this:

    I first thought of not showing the array at all to bypass the problem, but I needed to print the empty array because the libraries I'm using (google visualization) need the empty [].

    Jose Canciani

    • Piero Bond

      Piero Bond - 2009-06-13

      The better is to do like other code in same type body:

      FOR j IN 1..nvl(v_json_element_array.LAST,0)

      The simpler the better.

      • Jose Canciani

        Jose Canciani - 2009-06-13

        Thanks. I've done several other changes, for example I've included the date datatype and other minor fixes (for installing, since that out of the box the installation fails).
        I've lost the track of what I've added, but if you want I can send you the full code so you can merge it.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks