Oracle PL/SQL 日期时间数学 - 间隔
我已经使用像 {?EndDate} - INTERVAL '1' YEAR
这样的语法有一段时间了,我知道我最终会遇到一个问题,我就解决了它。我尝试执行DATE '2010-12-31' - INTERVAL '6' MONTH
,但由于没有 6 月 31 日而感到窒息。最有效且一致的编码方式是什么?虽然追踪做出这样做决定的人会更令人满意,但这是不切实际的。 :-)
I've been using syntax like {?EndDate} - INTERVAL '1' YEAR
for a while now, and I knew there was an issue that I was going to hit eventually, and I just hit it. I tried to do DATE '2010-12-31' - INTERVAL '6' MONTH
, and it choked because there's no June 31st. What's the most efficient and consistent way to code this? While tracking down the person who made the decision to do it this way would be more satisfying, it's impractical. :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定是否有一致的方式,因为这当然取决于有人认为是 6 个月。然而,恕我直言,可以安全地假设
add_months
是减去或添加月份的标准方法(至少在 Oracle 中):此表达式返回 2010 年 6 月 30 日(这是该月的最后一天( 12 月 31 日也是如此)。
I am not sure if there is a constistent way, since it certainly depends on what someone thinks is 6 months. Yet, imho, it is safe to assume that
add_months
is a standard way (at least in Oracle) to subtract or add months:This expression returns June 30th 2010 (which is the last day in that month (as is the 31st in december).