SQL 更新日期为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20012941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
updating date to null
提问by Manual
I am trying to update a enroll_date row to null and it is telling me "cannot update (%s) to NULL"
, so I tried doing putting TO_CHAR
and it still doesn't help...
我正在尝试将 enroll_date 行更新为 null 并且它告诉我"cannot update (%s) to NULL"
,所以我尝试进行放置TO_CHAR
但它仍然没有帮助...
enroll_date shows this which I want to make it to null
enroll_date 显示了我想将其设为 null
ENROLL_DATE
07-FEB-07
This is what I have
这就是我所拥有的
UPDATE ENROLLMENT
SET TO_CHAR(ENROLL_DATE) = NULL
WHERE STUDENT_ID ='125'
AND SECTION_ID ='61';
how can I set enroll_date to null ?
如何将 enroll_date 设置为 null ?
回答by gvee
Remove the TO_CHAR function. You're updating a column, not the function'd value
删除 TO_CHAR 函数。您正在更新列,而不是函数的值
UPDATE ENROLLMENT
SET ENROLL_DATE = NULL
WHERE STUDENT_ID ='125'
AND SECTION_ID ='61';
回答by Justin Cave
The error appears to be telling you that your data model defines enroll_date
as a NOT NULL
column. You cannot, therefore, set it to be NULL.
该错误似乎告诉您您的数据模型定义enroll_date
为一NOT NULL
列。因此,您不能将其设置为 NULL。
You could modify the table definition to allow NULL values
您可以修改表定义以允许 NULL 值
ALTER TABLE enrollment
MODIFY( enroll_date DATE NULL )
It seems likely, however, that this was an intentional choice made when defining the data model that should not be altered. I don't see how it would make sense to have an enrollment
without having an enroll_date
.
然而,这似乎是在定义不应更改的数据模型时有意做出的选择。我不明白如果enrollment
没有enroll_date
.
回答by Mihai
UPDATE ENROLLMENT
SET ENROLL_DATE = NULL
WHERE STUDENT_ID ='125'
AND SECTION_ID ='61';
If this does not work,you probably have the column definition NOT NULL.
如果这不起作用,您可能有列定义 NOT NULL。
回答by JarekMaxiM
use ALTER COLUMN instead of MODIFY
使用 ALTER COLUMN 而不是 MODIFY
ALTER TABLE enrollment<br/>
ALTER COLUMN enroll_date DATE NULL