----extract( month from diff) "month",------(adding this line gives error to the original code)
select extract( day from diff ) Days,
extract( hour from diff ) Hours,
extract( minute from diff ) Minutes
from (
select (CAST(creation_date as timestamp) - CAST(old_creation_date as timestamp)) diff
from [Table Name]
);
这段代码很容易理解。但有人可以在我尝试代码时解释如何计算月份,它给了我以下错误:
ORA-30076:提取源的提取字段无效
此问题已在本论坛中讨论过(月份除外,它不是我的代码,最初由https://stackoverflow.com/users/3651607/Andy-korneyev发布)。
答案 0 :(得分:1)
使用MONTHS_BETWEEN(date1, date2)
计算Oracle中的月差异。