How to replace all null values in Grade1 to 'Unknown' in SQL? This didn't work because Grade1 is number but 'Unknown' is char.
SELECT NVL(Grade1, 'Unknown')
FROM table;
[table]
Student Grade1 Grade2
1 NULL 0.88
2 0.80 0.50
3 NULL 0.40
You can't do just what you want. Both branches of
NVL()must return the same datatype. If you really want "Unknown" forNULLvalues, then you have to convert non-NULLvalues to strings as well.Assuming that you are running Oracle, as
NVL()suggests:That said, I would rather keep
NULLvalues as they are. This seems like the right way to represent the absence of data (NULLreally stands for "Unknown").