SQL日期时间:在Oracle和SQL Server上添加时间 [英] SQL Datetime: add time on Oracle and SQL Server

查看:99
本文介绍了SQL日期时间:在Oracle和SQL Server上添加时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL Server和Oracle Server上都具有数据库服务器,

Having database servers on both SQL Server and Oracle Server,

我找不到为日期添加时间的任何同类答案.

I couldn't find any homogeneous answer for adding time to a date.

我将在 SQL Server 上执行的操作:

select dateadd(minute, 1, CreationDate) from comments

Oracle服务器上(即使这不是一个很好的解决方案):

and on Oracle Server (even though this isn't a pretty solution):

select CreationDate + (1/1440) from comments

1440是一天中的分钟.

1440 being the minutes in a day.

有什么解决方案可同时在两台服务器上使用吗?

Is there any solution that would work on both servers?

推荐答案

我不知道这是否适用于Oracle,但这适用于SQL Server(已在2014年Ex.Edition上测试):

I don't know if this works on Oracle but this works on SQL Server (Tested on 2014 Ex. Edition):

select CreationDate + (1./1440) from comments

与oracle解决方案唯一不同的是1后面的点-只是告诉sql server这不是整数列,而是浮点数.

The only thing that's different to your oracle solution is the dot behind 1 - just to tell sql server that this is not an integer column but a float.

这篇关于SQL日期时间:在Oracle和SQL Server上添加时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆