基于 SYSDATE 的上个月 [英] Previous Month based on SYSDATE

查看:68
本文介绍了基于 SYSDATE 的上个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 PRTIME 的表,其中包含一个名为 TR_DATE 的日期字段.根据 SYSDATE,我需要查询 SYSDATE 之前一个月的 PRTIME 表.

I have a table called PRTIME with a date field called TR_DATE. Based on the SYSDATE, I need to query the PRTIME table for the month prior to SYSDATE.

在 SQL Server 中,我将执行以下操作:

In SQL Server I would do the following:

select * from PRTIME
WHERE datepart(month,TR_DATE) = datepart(month,dateadd(month,-1,current_timestamp))
and datepart(year,TR_DATE) = datepart(year,dateadd(month,-1,current_timestamp))

我将如何在 Oracle 中执行此操作?

How would I do this in Oracle?

推荐答案

我愿意

WHERE tr_date >= trunc( add_months( sysdate, -1 ), 'MM' )
  AND tr_date <  trunc( sysdate, 'MM' )

这篇关于基于 SYSDATE 的上个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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