将间隔转换为分钟
假设我有 2 个间隔:
INTERVAL '0 00:30:00' DAY TO SECOND
INTERVAL '0 04:00:00' DAY TO SECOND
获取每个间隔的分钟数的最优雅的方法是什么。相应地,30
和240
。
是的,我知道我可以执行 EXTRACT(HOUR FROM Interval) * 60 + EXTRACT(MINUTE FROM Interval),但这对我来说看起来很糟糕。
还有更好的解决方案吗?
Let's suppose I have 2 intervals:
INTERVAL '0 00:30:00' DAY TO SECOND
INTERVAL '0 04:00:00' DAY TO SECOND
What is the most elegant way to get amount of minutes in each interval. 30
and 240
accordingly.
Yes, I know I can perform EXTRACT(HOUR FROM interval) * 60 + EXTRACT(MINUTE FROM interval)
, but this looks terrible to me.
Any better solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在你看来很糟糕的事情,在我看来完全可以接受。如果您查看可以在 INTERVAL 上执行的算术的文档:
http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements001.htm#sthref175
然后您会看到可以将它们与数字相乘。因此,如果将间隔乘以 24 和 60,则可以通过提取天数来获得分钟数。它更紧凑,但我怀疑在您看来它是否更优雅。
问候,
抢。
What looks terrible to you, looks perfectly acceptable to me. If you look at the documentation at the arithmetic you can perform on INTERVALs:
http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements001.htm#sthref175
then you see you can multiply them with numerics. So if you multiply your intervals to 24 and 60, you can get the number of minutes by extracting the number of days. It's more compact, but I doubt if it's more elegant in your view.
Regards,
Rob.
别忘了几天。
Don't forget about days.
重用上面 Rob 的例子,
Reusing Rob's example above,