判断当前日期来决定是否执行sql 求助求助!! 本帖最后由 shunjiankunle 于 2012-04-27 10:56:07 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果表里面是时间字段select * from tab where to_char(date,'yyyy') = 输入的年份;这样是否可以另外,头像哪儿来的呀,好萌的妹子 统计当然是连年带月一起统计。你没表没数据,给个SQL有什么用,打几个田字格都能说明白的问题说不明白。 条件设成to_char(date,'yyyy-MM')<to_char(sysdate,'yyyy-MM')试试 传入一个参数 年份 构造一个月份表来左联你的表 查询每月数据select to_char(add_months(to_date('2011'||'01-01','yyyy-mm-dd'),level-1),'yyyy-mm') monfrom dualconnect by level <= (select case when 2011=to_char(sysdate,'yyyy') then to_number(to_char(sysdate,'mm')) else 12 end a from dual)--参数2011 mon-----------------1 2011-012 2011-023 2011-034 2011-045 2011-056 2011-067 2011-078 2011-089 2011-0910 2011-1011 2011-1112 2011-12--参数2012 mon-----------------1 2012-012 2012-023 2012-034 2012-04 这一大堆SQL看的人眼晕……下面是按自己理解写的-- 如果是往年的记录就显示12个月份的记录 如果是今年的就显示当前月份之前的记录,根据年份判断可以得出时间范围,一个开始时间,一个结束时间,以这两个时间作为条件查询--例如传入年份year(格式yyyy)--得到开始时间(闭区间):不管传入的是哪一年,肯定都是从传入年份的一月一日开始查select to_date(year||'0101','yyyymmdd') from dual;--得到结束时间(开区间):如果是往年,传入年份第二年的1月1日;如果是今年,本月1日select decode(to_number(to_char(sysdate, 'yyyy')) - to_number(year), 0, to_date(to_char(sysdate, 'yyyymm') || '01', 'yyyymmdd'), to_date((to_number(year) + 1) || '0101', 'yyyymmdd')) from dual;--比如时间字段是time,where条件就是:where time<decode(to_number(to_char(sysdate, 'yyyy')) - to_number(year), 0, to_date(to_char(sysdate, 'yyyymm') || '01', 'yyyymmdd'), to_date((to_number(year) + 1) || '0101', 'yyyymmdd'))and time>=to_date(year||'0101','yyyymmdd') 如何进行oracle10g的sql语句跟踪 Oracle DatabaseLink无法连接 Oracle 8i 解析顺序问题 求解 如何实现已下查询(内详) 通过imp导入一个没有数据的dmp文件(3M左右),本来还有2048M的表空间一下就满了? sql/plus中如何打印变量,使之显示出来 在8i里如何更改internal 的口令? 页面乱码问题 数据库连接 创建触发器权限不足?! 怎么能知道数据库中哪些函数、过程引用到了某个表? oracle循环读取
select * from tab where to_char(date,'yyyy') = 输入的年份;
这样是否可以
另外,头像哪儿来的呀,好萌的妹子
统计当然是连年带月一起统计。你没表没数据,给个SQL有什么用,打几个田字格都能说明白的问题说不明白。
from dual
connect by level <= (select case when 2011=to_char(sysdate,'yyyy') then to_number(to_char(sysdate,'mm')) else 12 end a from dual)
--参数2011
mon
-----------------
1 2011-01
2 2011-02
3 2011-03
4 2011-04
5 2011-05
6 2011-06
7 2011-07
8 2011-08
9 2011-09
10 2011-10
11 2011-11
12 2011-12
--参数2012
mon
-----------------
1 2012-01
2 2012-02
3 2012-03
4 2012-04
--例如传入年份year(格式yyyy)--得到开始时间(闭区间):不管传入的是哪一年,肯定都是从传入年份的一月一日开始查
select to_date(year||'0101','yyyymmdd') from dual;--得到结束时间(开区间):如果是往年,传入年份第二年的1月1日;如果是今年,本月1日
select decode(to_number(to_char(sysdate, 'yyyy')) - to_number(year),
0,
to_date(to_char(sysdate, 'yyyymm') || '01', 'yyyymmdd'),
to_date((to_number(year) + 1) || '0101', 'yyyymmdd'))
from dual;
--比如时间字段是time,where条件就是:where time<decode(to_number(to_char(sysdate, 'yyyy')) - to_number(year),
0,
to_date(to_char(sysdate, 'yyyymm') || '01', 'yyyymmdd'),
to_date((to_number(year) + 1) || '0101', 'yyyymmdd'))
and time>=to_date(year||'0101','yyyymmdd')