How to modify the value of the fields of a column?

4

I have a simple question but I could not find a solution.

In the same way I can when I use select to bring an empty column using select a.x,NULL as y,a.z from DADOS a , how can I make a column instead of having only NULL , be filled in with some word from my school? / p>     

asked by anonymous 12.08.2016 / 01:47

2 answers

5

You can use CASE in select :

select a.x,
       NULL as y,
       CASE a.z 
           WHEN NULL THEN 'Vazio'
           ELSE a.z
       END as c          

from DADOS a
    
12.08.2016 / 01:58
1

In MySQL you can use the IFNULL () function, As follows:

SELECT IFNULL(UnitsOnOrder,0))
FROM Products

When the UnitsOnOrder field is null the value will be changed to 0. IFNULL can receive several types of parameters between them integers and strings.

If the field is a string where the values can contain both null and Empty you can use the expression.

SELECT IF(field1 IS NULL or field1 = '', 'empty', field1) as field1 
from tablename

For other databases there are similar functions that can be seen here .

    
12.08.2016 / 12:02