我有一个表字段是这样的
id        number
f_date    timestamp
status    number      (0或者1)我想要在f_date这个字段里面插入今后10年的所有日期 (差不多是365*10天)
有什么好办法吗?

解决方案 »

  1.   


    insert into t(id,f_date,status)
    select level,trunc(current_timestamp)+level,0
      from dual
     connect by level <= months_between(trunc(current_timestamp),120)-trunc(current_timestamp);
      

  2.   

    insert into t(f_date)
    SELECT SYSDATE+ROWNUM FROM DUAL CONNECT BY ROWNUM<4000
      

  3.   

    大奔哥的句子跑起来报错,ORA-00932: inconsistent datatypes: expected DATE got NUMBER
    改成add_months就好了
    select level,trunc(current_timestamp)+level,0
      from dual
     connect by level <= add_months(trunc(current_timestamp),120)-trunc(current_timestamp)
      

  4.   

    谢谢楼上3位 3L的加上非空字段就可以用了 而且很简洁呀~为什么4L的运行后 id和日期不是对应的从小到大呢?要是能帮我解释下这段sql的原理就好了 
      

  5.   

    select level,trunc(current_timestamp)+level,0
      from dual
     connect by level <= add_months(trunc(current_timestamp),120)-trunc(current_timestamp)
    --current_timestamp取当前系统时间戳
    --trunc(current_timestamp)取到当天零时
    --connect by 递归调用
    --level递归的层
    --add_months日期函数,加n个月后是哪天
      

  6.   


    就是想写 add_months 的,手误。。