Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

empty string is not the same as null

Anton SchefferJun 12 2020 — edited Jun 12 2020

I just noticed that an empty string is not the same as null, at least for the PLSQL json_object_t type on a 12.2.0.1.0 database

See for instance

declare

  l_json      json_object_t;

  l_x varchar2(10);

begin

      l_json := json_object_t();

      l_json.put( 'a', '' );

      l_json.put( 'b', to_char( null ) );

      l_json.put( 'c', l_x );

      l_json.put( 'd', nvl(l_x,'') );

      l_x := null;

      l_json.put( 'e', l_x );

      l_x := '';

      l_json.put( 'f', l_x );

      dbms_output.put_line( l_json.to_string );

end;

{"a":"","b":null,"c":null,"d":"","e":null,"f":""}

Does anyone know if this is documented somewhere?

The only thing I can find says the opposite: zero length character value is treated as null: https://docs.oracle.com/database/121/SQLRF/sql_elements005.htm#SQLRF30037

Comments
Post Details
Added on Jun 12 2020
13 comments
4,956 views