PL/SQL treads zerolength string as NULL values
Join the DZone community and get the full member experience.Join For Free
There is no such thing as a zero-length string in Oracle PL/SQL. A zero-length string would always result in a NULL-String. The code above tests and proves this.
You should not use a comparison operator like =, <>, <, > before asserting that both strings used in the expression are not NULL. See the further comment on:
If your coding in different languages is parallel, this statement is especially important to be aware of.
SQL Reporting specialist
declare str varchar2(128); begin str := null; dbms_output.put_line('sample-1>>' || length(str)|| '<<'); str := ''; dbms_output.put_line('sample-2>>' || length(str)|| '<< !!!'); if length(str) = 0 then dbms_output.put_line('String length is 0'); else dbms_output.put_line('String length is undefined'); end if; dbms_output.put_line ('Where as non-empty strings perform as excepted'); str := 'A';dbms_output.put_line( str || '>>' || length(str)); str := 'Beware of dealing with zerolenght strings in PL/SQL '; dbms_output.put_line( str || '>>' || length(str)|| '<<'); end;
Opinions expressed by DZone contributors are their own.