MySql Query Replace NULL with Empty String in Select

后端 未结 11 1165
天命终不由人
天命终不由人 2021-02-01 11:36

How do you replace a NULL value in the select with an empty string? It doesnt look very professional to output \"NULL\" values.

This is very unusual and based on my synt

相关标签:
11条回答
  • 2021-02-01 12:17

    Try this, this should also get rid of those empty lines also:

    SELECT prereq FROM test WHERE prereq IS NOT NULL;
    
    0 讨论(0)
  • 2021-02-01 12:18

    Try below ;

      select if(prereq IS NULL ," ",prereq ) from test
    
    0 讨论(0)
  • 2021-02-01 12:19

    I have nulls (NULL as default value) in a non-required field in a database. They do not cause the value "null" to show up in a web page. However, the value "null" is put in place when creating data via a web page input form. This was due to the JavaScript taking null and transcribing it to the string "null" when submitting the data via AJAX and jQuery. Make sure that this is not the base issue as simply doing the above is only a band-aid to the actual issue. I also implemented the above solution IFNULL(...) as a double measure. Thanks.

    0 讨论(0)
  • 2021-02-01 12:21

    If you really must output every values including the NULL ones:

    select IFNULL(prereq,"") from test
    
    0 讨论(0)
  • 2021-02-01 12:24

    I know this is old question but i got best solution without change query and also support for SELECT * statement

    foreach ($row as &$value) {
      if($value==null){
         $value="";
      }
    }
    
    0 讨论(0)
  • 2021-02-01 12:24
    UPDATE your_table set your_field="" where your_field is null
    
    0 讨论(0)
提交回复
热议问题