Saturday, June 22, 2013

SQL Server Vs Oracle: Handling of empty string and nulls.

In Oracle database empty string gets treated as null.

DECLARE v_name NVARCHAR2(16);
BEGIN
  
  v_name := 'xyz';
  IF( v_name != '') THEN
    dbms_output.put_line ('Valid comparison');
  ELSE
    dbms_output.put_line ('Impossible');
  END IF;  
  
  IF ('' IS NULL) THEN
    dbms_output.put_line ('Empty string as null');
  END IF;

END;


This is different from behaviour of SQL Server. SQL server treats empty string as not null.

No comments: