添加年份并移至最后一天
某些事件需要在年底之前发生,即距离上一次事件已有 10 年。我发出这样的查询来计算截止日期:
SELECT
:previous_date AS previous_date,
ADD_MONTHS(
TO_DATE(
EXTRACT(
YEAR FROM TO_DATE(:previous_date, 'YYYY-MM-DD HH24-MI-SS')
) || '-12-31 23-59-59', 'YYYY-MM-DD HH24-MI-SS'
), 12*10
) AS deadline
FROM DUAL
例如:
PREVIOUS_DATE DEADLINE
------------- -------------------------
2008-07-15 31/12/2018 23:59:59
到目前为止我工作得很好但是......我是否缺少一些可以使查询更具可读性的功能?
Certain event needs to happen before the end of the year when it's 10 years since the previous event. I'm issuing a query like this to calculate the deadline:
SELECT
:previous_date AS previous_date,
ADD_MONTHS(
TO_DATE(
EXTRACT(
YEAR FROM TO_DATE(:previous_date, 'YYYY-MM-DD HH24-MI-SS')
) || '-12-31 23-59-59', 'YYYY-MM-DD HH24-MI-SS'
), 12*10
) AS deadline
FROM DUAL
E.g.:
PREVIOUS_DATE DEADLINE
------------- -------------------------
2008-07-15 31/12/2018 23:59:59
I works fine so far but... Am I missing some function that can make the query more readable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 trunc 来得到
(1/1440) 减去 11 年的一秒,给您 23:59:59
You could use the trunc so that you get
The (1/1440) takes a second off the 11 years, to give you 23:59:59