如何在 Derby 中的 SQL 中为日期类型列返回 NULL 值?
在我的 Sql 中,我想按具有某些条件的某些列进行分组,因此对于其他列,它们是日期类型。我只想手动为它们返回 null,但我不知道如何。 您能给我一些如何为日期类型列返回 null 的建议吗?简单地使用 NULL 在 Apache Derby 中不起作用,这很奇怪。
我也对其他数据库的答案感兴趣。如果你也能回答的话那就太好了。
编辑
回复评论,我想要 select NULL from TABLE
,NULL代表DATE类型列的空值。我只想手动返回 NULL 值。但它抛出异常告诉我 NULL 无效。这可能吗?
编辑
我找到了一种解决方法,可以在 Derby 中返回日期类型的常量值。即使用 Date(789)
,它是 derby 中的日期函数。但我仍然对如何为 Date 返回空常量值感兴趣?
Derby 中的查询中的编辑
NULL
必须转换为正确的类型。这有点不同。
In my Sql, I want to group by some columns having some conditions , so for other column, they are date type. I just want to manually return null for them, But i don't know how.
Can you give me some advice how to return null for date type column? To simply use NULL doesn't work in Apache Derby which is odd.
I am also interested in the answer for other database. If you can also answer it, it will be great.
EDIT
Reply to comment, I wantselect NULL from TABLE
, and NULL stands for an empty value of DATE type column. I just want to return a NULL value manually.But it throws exception tells me NULL is invalid. Is that possible?
EDIT
I found an workaround to return a constant value for date type in Derby. That is using Date(789)
which is date function in derby. But I am still insterested in how to return an empty constant value for Date?
EDIT
NULL
in query in Derby must be casted to correct type. which is a bit different.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它应该使用
cast(null as DATE) AS START_DATE
表达式。如链接中所示。我只是添加在这里,以便其他人轻松找到它。一件有趣的事情是,即使
START_DATE
列是NOT NULL
,我仍然可以伪造该列的NULL
返回值。其实应该是这样,一点也不奇怪,对吧?It should use
cast(null as DATE) AS START_DATE
expression. As in the link.I just add here for others to find it out easily. One thing interesting is even the column
START_DATE
isNOT NULL
, I can still fake aNULL
return value for this column. Actually it should be , not a surprise at all here,right?由于您的列可以为 NULL,因此您应该将该属性声明为 DateTime 可空:
DateTime?我的日期;
Since your column is NULL-able you should declare the property also as DateTime nullable:
DateTime? MyDate;