Explicitly return text "NULL" in MySQL query when result is NULL

0

How would I write a SQL query in a MySQL environment where I explicitly replace all NULL values returned my query with the word NULL?

THE DOCTOR

Posted 2017-07-18T20:53:32.080

Reputation: 191

3

Or, don't... http://www.bbc.com/future/story/20160325-the-names-that-break-computer-systems

– Arjan – 2017-07-18T21:02:44.113

This is a terrible idea... a zero-length string might be somewhat acceptable, but the correct solution is to handle NULLs properly in your application. – Attie – 2018-10-02T11:38:11.710

Answers

1

SELECT COALESCE( yourNullValue , 'NULL') FROM whatever

COALESCE(value,...)

Returns the first non-NULL value in the list, or NULL if there are no non-NULL values.

The return type of COALESCE() is the aggregated type of the argument types.

Source: https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#function_coalesce

Steven

Posted 2017-07-18T20:53:32.080

Reputation: 24 804

Functional, but please include a note indicating how much of a bad idea this is. – Attie – 2018-10-02T11:38:33.113