Let's say that the record comes from a form to gather name and address information. Line 2 of the address will typically be blank if the user doesn't live in apartment. An empty string in this case is perfectly valid. I tend to prefer to use NULL to mean that the value is unknown or not given.

I don't believe the physical storage difference is worth worrying about in practice. As database administrators, we have much bigger fish to fry!

Answer from Larry Coleman on Stack Exchange
Top answer
1 of 11
94

Let's say that the record comes from a form to gather name and address information. Line 2 of the address will typically be blank if the user doesn't live in apartment. An empty string in this case is perfectly valid. I tend to prefer to use NULL to mean that the value is unknown or not given.

I don't believe the physical storage difference is worth worrying about in practice. As database administrators, we have much bigger fish to fry!

2 of 11
28

I do not know about MySQL and PostgreSQL, but let me treat this a bit generally.

There is one DBMS namely Oracle which doesn't allow to choose it's users between NULL and ''. This clearly demonstrates that it is not necessary to distinguish between both. There are some annoying consequences:

You set a varchar2 to an empty string like this:

Update mytable set varchar_col = '';

the following leads to the same result

Update mytable set varchar_col = NULL;

But to select the columns where the value is empty or NULL, you have to use

select * from mytable where varchar_col is NULL;

Using

select * from mytable where varchar_col = '';

is syntactically correct, but it never returns a row.

On the other side, when concatenating strings in Oracle. NULL varchars are treated as empty strings.

select NULL || 'abc' from DUAL;

yields abc. Other DBMS would return NULL in these cases.

When you want to express explicitly, that a value is assigned, you have to use something like ' '.

And you have to worry whether trimming not empty results in NULL

select case when ltrim(' ') is null then 'null' else 'not null' end from dual

It does.

Now looking at DBMS where '' is not identical to NULL (e.g. SQL-Server)

Working with '' is generally easier and in most case there is no practical need to distinguish between both. One of the exceptions I know, is when your column represents some setting and you have not empty defaults for them. When you can distinguish between '' and NULL you are able to express that your setting is empty and avoid that the default applies.

🌐
GitHub
github.com › colinhacks › zod › issues › 1721
How to transform empty strings into null? `z.emptyStringToNull()` · Issue #1721 · colinhacks/zod
December 18, 2022 - import { afterAll, beforeAll } from 'vitest'; import { z } from 'zod'; describe('Test zod validations', () => { it('should correctly handles a valid ISO date-string', () => { const valid_from = '2022-12-14T22:07:10.430805+00:00'; const valid_to = undefined; <-- this works const valid_to = null; <-- this works const valid_to =""; <-- this is not working const schema = z.string().datetime({ offset: true }).nullish(); expect(schema.parse(valid_from)).toStrictEqual(valid_from); expect(schema.parse(valid_to)).toStrictEqual(valid_to); }); });
Author: colinhacks
Discussions

java - Get empty string when null - Stack Overflow
Returns either the passed in String, or if the String is null, an empty String (""). If you also want to get rid of "null", you can do: More on stackoverflow.com
🌐 stackoverflow.com
Use "+ string.Empty" or "?.ToString() ?? string.Empty" for a nullable object
string s = abc + string.Empty; That just looks like a weird line to have in code, without the context that it's handling the case that your string is null. I would personally go with something that looks more like an explicit null test; clarity of why the code exists is more important, in my opinion. That's without even thinking about the performance implications; I would expect a null check to be cheaper than string concatenation, even with an empty string. More on reddit.com
🌐 r/csharp
122
58
July 10, 2025
Null is converted to empty string when writing to database.
While updating a table from the process model using WriteToDatastoreEntity node. Even though CDT fields are null, it is updating empty string value in the table More on community.appian.com
🌐 community.appian.com
4
0
November 12, 2018
Replace empty string to null in form submit, and JS limitation in Changeset Object
I might be asking trivial questions but I really couldn't figure them out In a very simple pgsql form submit, some of foreign key need to be null instead of "" otherwise I get below error My first thought is to use … More on community.retool.com
🌐 community.retool.com
1
1
December 18, 2023
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.componentmodel.dataannotations.displayformatattribute.convertemptystringtonull
DisplayFormatAttribute.ConvertEmptyStringToNull Property (System.ComponentModel.DataAnnotations) | Microsoft Learn
<DisplayFormat(ConvertEmptyStr... value. Use the ConvertEmptyStringToNull property to specify whether an empty string value is automatically converted to null when the data field is updated in the database....
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.string.isnullorempty
String.IsNullOrEmpty(String) Method (System) | Microsoft Learn
It is equivalent to the following code: bool TestForNullOrEmpty(string s) { bool result; result = s == null || s == string.Empty; return result; } string s1 = null; string s2 = ""; Console.WriteLine(TestForNullOrEmpty(s1)); Console.WriteLine(TestForNullOrEmpty(s2)); // The example displays the following output: // True // True
🌐
Reddit
reddit.com › r/csharp › use "+ string.empty" or "?.tostring() ?? string.empty" for a nullable object
r/csharp on Reddit: Use "+ string.Empty" or "?.ToString() ?? string.Empty" for a nullable object
July 10, 2025 -

The Title basically says it all. If an object is not null, calling ".ToString()" is generally considered better than "+ string.Empty", but what about if the object could be null and you want a default empty string.

To me, saying this

void Stuff(MyObject? abc)
{
  ...
  string s = abc?.ToString() ?? string.Empty;
  ...
}

is much more complex than

void Stuff(MyObject? abc)
{
  ...
  string s = abc + string.Empty;
}

The 2nd form seems to be better than the 1st, especially if you have a lot of them.

Thoughts?

----

On a side note, something I found out was if I do this:

string s = myNullableString + "";

is the same thing as this

string s = myNullableString ?? "";

Which makes another branch condition. I'm all for unit testing correctly, but defaulting to empty string instead of null shouldn't really add another test.

using string.Empty instead of "" is the same as this:

string s = string.Concat(text, string.Empty);

So even though it's potentially a little more, I feel it's better as there isn't an extra branch test.

EDIT: the top code is an over simplification. We have a lot of data mapping that we need to do and a lot of it is nullable stuff going to non-nullable stuff, and there can be dozens (or a lot more) of fields to populate.

There could be multiple nullable object types that need to be converted to strings, and having this seems like a lot of extra code:

Mydata d = new()
{
  nonNullableField = x.oneField?.ToString() ?? string.Empty,
  anotherNonNullableField = x.anotherField?.ToString() ?? string.Empty,
  moreOfThesame = x.aCompletelyDifferentField?.ToString() ?? string.Empty,
  ...
}

vs

Mydata d = new()
{
  nonNullableField= x.oneField + string.Empty, // or + ""
  anotherNonNullableField= x.anotherField + string.Empty,
  moreOfThesame = x.aCompletelyDifferentField + string.Empty,
  ...
}

The issue we have is that we can't refactor a lot of the data types because they are old and have been used since the Precambrian era, so refactoring would be extremely difficult. When there are 20-30 lines that have very similar things, seeing the extra question marks, et al, seems like it's a lot more complex than simply adding a string.

Find elsewhere
🌐
Oracle
docs.oracle.com › javaee › 7 › tutorial › bean-validation002.htm
21.2 Validating Null and Empty Strings - Java Platform, Enterprise Edition: The Java EE Tutorial (Release 7)
In this case, an empty string will pass this validation constraint. However, if you set the context parameter javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL to true, the value of the managed bean attribute is passed to the Bean Validation runtime as a null value, causing the @NotNull constraint to fail.
🌐
Retool
community.retool.com › 💬 app building
Replace empty string to null in form submit, and JS limitation in Changeset Object - 💬 App Building - Retool Forum
December 18, 2023 - I might be asking trivial questions but I really couldn't figure them out In a very simple pgsql form submit, some of foreign key need to be null instead of "" otherwise I get below error My first thought is to use inline js to replace "" with null inside Changeset -> Object -> {{form.data}}, but immediately I get run into a error object.keys() is not a function shown in below screenshot.
🌐
Abel
coding.abel.nu › 2013 › 01 › on-null-or-why-empty-strings-are-not-same-as-null
On Null or Why Empty Strings are not Same as Null – Passion for Coding
A SQL NVARCHAR() NULL can be either empty or null. If you allow the string to be null you’d better have a strict definition of how null is different to an empty string. There might be cases where null means unspecified while an empty string means specified as empty.
Top answer
1 of 4
12

This says it all:

select NVL('','it is null') as value
from dual;

SQL Fiddle

2 things:

1) '' gets converted to NULL on insert. That's an Oracle VARCHAR2 thing.

2) select * from test where f=''; is trying to do select * from test where f=NULL, which isn't defined, and will return nothing because NULL doesn't like the equality operator. You have to use IS NULL or IS NOT NULL.

I'll add that the CHAR datatype behaves differently because it is padded.

2 of 4
8

Oracle treats '' and NULL the same. When inserting '', there is no conversion of '' to NULL, merely an interpretation of '' as NULL in the same way that the word NULL is interpreted as NULL or rtrim('a','a') is interpreted as NULL.

Here is a demonstration using the following table and insert:

drop table t1;
create table t1 (c1 varchar2(10));
insert into t1 (c1) values ('');

The insert above inserted a NULL value for c1. You can select that row as follows:

SELECT c1 FROM t1;

When you add a WHERE clause to compare equality and one of the values being compared is NULL, the result will always be unknown. Unknown will evaluate to false except that further operations on an unknown value produce unknown values. All of the following return no rows because the WHERE clauses contain conditions that will never be true regardless of the data.

SELECT c1 FROM t1 WHERE c1 = '';
SELECT c1 FROM t1 WHERE c1 = NULL;
SELECT c1 FROM t1 WHERE '' = '';
SELECT c1 FROM t1 WHERE NULL = NULL;

Oracle provides a special syntax to retrieve rows with a particular column having null values -- IS NULL.

SELECT c1 FROM t1 WHERE c1 IS NULL;

There are a few conditions in which oracle compares NULLS treating them as equal to other NULL values such as in DECODE statements and in compound keys.

More information can be found in the SQL Language Reference.

🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.string.empty
String.Empty Field (System) | Microsoft Learn
In application code, this field is most commonly used in assignments to initialize a string variable to an empty string. To test whether the value of a string is either null or String.Empty, use the IsNullOrEmpty method.
🌐
Baeldung
baeldung.com › home › java › java string › difference between null and empty string in java
Difference Between null and Empty String in Java | Baeldung
April 19, 2024 - If we assign null to a String object, it’s initialized but not instantiated and hence holds no value or reference. An empty String is a valid String object having no characters, and as a result, all the String operations are available on this object.
🌐
Guava
guava.dev › releases › 20.0 › api › docs › com › google › common › base › Strings.html
Strings (Guava: Google Core Libraries for Java 20.0 API)
Or, if you'd like to normalize "in the other direction," converting empty strings to null, you can use emptyToNull(java.lang.String).
🌐
C For Dummies
c-for-dummies.com › blog
Null Versus Empty Strings | C For Dummies Blog
You must compare the two: Create an empty string or null string as a sample, then use the strcmp() function to compare them.