数据库:DB2 v9.5.301.436
要求:我需要查找一个月内的天数。
代码:
select day(last_day(created))
from tablename
错误:
[Error Code: -440, SQL State: 42884] DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884, SQLERRMC=LAST_DAY;FUNCTION, DRIVER=3.57.82. 2)
[Error Code: -727, SQL State: 56098] DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-440;42884;LAST_DAY|FUNCTION, DRIVER=3.57.82
我检查了DB2文档,其中显示了上述功能。 http://www-01.ibm.com/support/knowledgecenter/api/content/SSEPEK_10.0.0/com.ibm.db2z10.doc.sqlref/src/tpc/db2z_bif_lastday.html
答案 0 :(得分:0)
以下对我来说很好。
select day(last_day(current_timestamp))
from SYSIBM.SYSDUMMY1
您确定created
是约会对象吗?
答案 1 :(得分:0)
以下代码对我有用。
select day(date(date(created))-(day(date(created)) -1) days + 1 month -1 day) as maxdate , created from customer ;
注意:创建的列是timestamfild
如果创建日期,请使用以下查询。
select day(date(created)-(day(created) -1) days + 1 month -1 day) as maxdate , created from customer ;
答案 2 :(得分:0)
last_day在9.7中介绍。你可以自己滚动:
create function myfun.last_day(d date)
returns date
return (d + 1 month) - day(d + 1 month) days
with t(d) as (
values date('2014-01-11')
union all
select d + 1 month
from t
where d<'2015-01-01'
)
select d, myfun.last_day(d) from t