Fix for handling null CLOBs in json_value()

Herb Swift
2012-06-15
2013-05-28
  • Herb Swift
    Herb Swift
    2012-06-15

    I was having trouble in json_dyn.executelist when my result set included null CLOBs.  I traced the problem to the json_value type, specifically the following overload:

    CONSTRUCTOR FUNCTION json_value(str CLOB, esc BOOLEAN DEFAULT TRUE)

    The problem is that an attempt is made to read a null CLOB starting at position 1:

          DBMS_LOB.read(
            str
           ,amount
           ,1
           ,self.str
          );

    To fix this, I wrapped the attempt in an IF:

        IF dbms_lob.getlength(str) > 0 THEN
          DBMS_LOB.read(
            str
           ,amount
           ,1
           ,self.str
          );
        END IF;

    Since self.str is already null, this handles it fine for me.  Is this the best fix?  If so, I'd like to offer it for the next release of this excellent product.  Thanks for all of your hard work!

     

  • Anonymous
    2013-05-08

    I'm having the same problem with null clobs, but I can't seem to locate this code to apply your fix.  Where would I find JSON_VALUE?

     

  • Anonymous
    2013-05-08

    Never mind.  I found it, and notsoswift's patch worked like a charm.

    json_value_body.typ (Line 34):

        34      if(dbms_lob.getlength(str) > 0) then
        35        dbms_lob.read(str, amount, 1, self.str);
        36      end if;