How to store NULL values in datetime fields in MySQL?

后端 未结 8 544
再見小時候
再見小時候 2020-11-29 05:44

I have a \"bill_date\" field that I want to be blank (NULL) until it\'s been billed, at which point the date will be entered.

I see that MySQL does not like NULL val

8条回答
  •  广开言路
    2020-11-29 06:33

    For what it is worth: I was experiencing a similar issue trying to update a MySQL table via Perl. The update would fail when an empty string value (translated from a null value from a read from another platform) was passed to the date column ('dtcol' in the code sample below). I was finally successful getting the data updated by using an IF statement embedded in my update statement:

        ...
        my $stmnt='update tbl set colA=?,dtcol=if(?="",null,?) where colC=?';
        my $status=$dbh->do($stmt,undef,$iref[1],$iref[2],$iref[2],$ref[0]);
        ...
    

提交回复
热议问题