Thursday, June 05, 2025

JSON_OBJECT_T.GET_CLOB(key) returns the string 'null' if the value is null

Discovery of the day on Oracle 19 version EE 19.21.0.0.0:

JSON_OBJECT_T.GET_CLOB(key) member function returns a CLOB string containing 'null' (lowercase), not a NULL value.

As you can see below the 'null' string is matched by the function NULLIF which replaces it with a real NULL value:

set serveroutput on
declare
  l_procedure clob;
  j_job_desc       json_object_t;
begin
  j_job_desc := json_object_t.parse('{"procedure":null}');
  l_procedure := nullif(j_job_desc.get_clob('procedure'),'null');
  if l_procedure is null then
    dbms_output.put_line('nothing');
  else
    dbms_output.put_line(l_procedure);
  end if;
end;
/

nothing


PL/SQL procedure successfully completed.
The documentation doesn't explain this behavior at all, it just says that the member function will create a CLOB implicitly and that's all,

No comments:

Post a Comment

I appreciate your comment however bear in mind that I might not have the time to reply soon.
Normally I do not reply to all comments but I am glad if you found something useful or if you learned something new, in that case I strongly encourage you to promote the article with the +1 google button.
Flavio