比如说,我输入时间段是  2011-01-01 到 2011-01-03
那么就应该把 2011-01-01 、2011-01-02 、2011-01-03 这三个日期插入,到数据库表中,现在数据库就增加了三条数据,请问如何实现比较好啊?

解决方案 »

  1.   


    declare
        begintime       date;
        endtime         date;
    begin
        begintime := to_date('2011-01-01','yyyy-mm-dd');
        endtime := to_date('2011-01-03','yyyy-mm-dd');
        
        while (begintime <= endtime)
        loop
            dbms_output.put_line(to_char(begintime,'yyyy-mm-dd'));
            begintime := begintime + 1;
        end loop;
    end;
    /
    2011-01-01
    2011-01-02
    2011-01-03
     
    PL/SQL procedure successfully completed
     
      

  2.   


    create procedure pro_dt(@sart datetime,@end datetime)
    as
    declare @dt as int,@diff as int
    set @dt=datediff(day,@sart,@end)
    set @diff=0
    while @dt>0
    begin
    insert into dt select dateadd(day,@diff,@sart)
    set @diff=@diff+1
    set @dt=@dt-1
    end
    goexec pro_dt '2011-02-01','2011-03-01'
      

  3.   

    学习,修改
    drop proc pro_dtcreate procedure pro_dt(@start datetime,@end datetime)
    as
    while @start<=@end
    begin
    insert into dt select @start
    set @start=@start+1
    end
    go
    exec pro_dt '2011-02-01','2011-03-01'
      

  4.   

    insert into 表名 (时间字段)
    select to_date('2011/08/20', 'yyyy/mm/dd') + rownum - 1  
      from dual 
    connect by rownum <= to_date('2011/09/20', 'yyyy/mm/dd') - to_date('2011/08/20', 'yyyy/mm/dd') + 1;