表report
字段     描述  值
tj_year  年    2011
tj_month  月   1
这2个字段都是varchar2,需要根据这2个字段删除一年前的数据,请oracle sql语句

解决方案 »

  1.   

    delete from table1 where tj_year<add_month(tj_year,-1)
      

  2.   


    delete from report where tj_year || lpad(tj_month, 2, '0') < to_char(add_months(sysdate, -12), 'yyyymm');
      

  3.   

    -- 删除一年前的数据:
    -- (如果要删除的记录不包括去年的当前月,例如:现在是2011年9月),则操作如下:
     delete from report where  tj_year||lpad(tj_month,2,'0')< to_char(add_months(sysdate,-12),'yyyymm');-- (如果要删除的记录包括去年的当前月,例如:现在是2011年9月),则操作如下:
     delete from report where  tj_year||lpad(tj_month,2,'0')<=to_char(add_months(sysdate,-12),'yyyymm');
      

  4.   

    delete from report t 
    where to_date((t.tj_year || (case when to_number(t.tj_month)<10 then '0'||to_number(t.tj_month) else t.tj_month end)),'yyyy-mm') <add_months(sysdate,-12)
    由于不知道你的 tj_month 字段中的存值情况,是‘01’还是‘1’,所以用to_number判断了一下。算法比较笨拙,抛砖引玉一下。