上个月的Oracle日期函数 [英] Oracle date function for the previous month

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

问题描述

我在下面的查询中对日期进行了硬编码.我的目标是删除编码日期;该查询在运行时应提取上个月的数据.

I have the query below where the date is hard-coded. My objective is to remove the harcoded date; the query should pull the data for the previous month when it runs.

select count(distinct switch_id)
  from xx_new.xx_cti_call_details@appsread.prd.com
 where dealer_name =  'XXXX'
   and TRUNC(CREATION_DATE) BETWEEN '01-AUG-2012' AND '31-AUG-2012'

我应该为此使用sysdate-15函数吗?

Should I use sysdate-15 function for that?

推荐答案

稍微修改Ben的查询,

Modifying Ben's query little bit,

 select count(distinct switch_id)   
  from xx_new.xx_cti_call_details@appsread.prd.com  
 where dealer_name =  'XXXX'    
   and creation_date between add_months(trunc(sysdate,'mm'),-1) and last_day(add_months(trunc(sysdate,'mm'),-1))

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

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