DATEDIFF function in Oracle(Oracle 中的 DATEDIFF 函数)
问题描述
我需要使用 Oracle,但 DATEDIFF 函数在 Oracle DB 中不起作用.
I need to use Oracle but DATEDIFF function doesn't work in Oracle DB.
如何在Oracle中编写以下代码?我看到了一些使用 INTERVAL 或 TRUNC 的示例.
How to write the following code in Oracle? I saw some examples using INTERVAL or TRUNC.
SELECT DATEDIFF ('2000-01-01','2000-01-02') AS DateDiff;
推荐答案
在 Oracle 中,您可以简单地减去两个日期并获得 天 的差值.另请注意,与 SQL Server 或 MySQL 不同,在 Oracle 中,您不能在没有 from 子句的情况下执行 select 语句.解决这个问题的一种方法是使用内置的虚拟表,dual:
In Oracle, you can simply subtract two dates and get the difference in days. Also note that unlike SQL Server or MySQL, in Oracle you cannot perform a select statement without a from clause. One way around this is to use the builtin dummy table, dual:
SELECT TO_DATE('2000-01-02', 'YYYY-MM-DD') -
TO_DATE('2000-01-01', 'YYYY-MM-DD') AS DateDiff
FROM dual
这篇关于Oracle 中的 DATEDIFF 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Oracle 中的 DATEDIFF 函数
基础教程推荐
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
