由一个excel电子表格其中有字段“开始日期”,“开始时间”和“时长”三个字段开始日期          开始时间    时长
2010-01-01 09:10:55    39
2010-01-01 12:19:02    0 
2010-01-01 12:42:38    0 
2010-01-01 14:54:08    57将以上表格导入oracle数据库后问题一:如何让开始日期字段和开始时间字段合并,整合为开始时间。
问题二:如何添加结束时间字段,也就是开始时间+时长,时长的单位为秒如何使用sql语句实现以上问题,请各位老师不吝赐教。谢谢!

解决方案 »

  1.   

    如果导入后开始日期,开始时间为字符型,表名为table1create table2 as
    select to_date(开始日期||' '||开始时间,'yyyy-mm-dd hh24:mi:ss'),时长,
    to_date(开始日期||' '||开始时间,'yyyy-mm-dd hh24:mi:ss')+时长/86400 结束时间
    from table1;
      

  2.   

    --这个
    create table2 as
    select to_date(开始日期||' '||开始时间,'yyyy-mm-dd hh24:mi:ss') 开始时间,时长,
    to_date(开始日期||' '||开始时间,'yyyy-mm-dd hh24:mi:ss')+时长/86400 结束时间
    from table1;
      

  3.   


    还是不行结果为
    开始时间                      时长  结束时间                      
    ------------------------- --- ------------------------- 
    10-1月 -10                53  10-1月 -10                
    10-1月 -10                43  10-1月 -10                
    10-1月 -10                0   10-1月 -10                
    10-1月 -10                0   10-1月 -10                
    10-1月 -10                35  10-1月 -10            仍然没有变成yyyy-mm-dd hh24:mi:ss何故?请耐心指教,谢谢!
      

  4.   

    你没有设置日期格式啊 alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';或者 alter system set nls_date_format='yyyy-mm-dd hh24:mi:ss';
      

  5.   

    学习,COPY走~create table TB2 as 
    select to_date(开始日期||' '||开始时间,'yyyy-mm-dd hh24:mi:ss') 开始时间,
           时长,
           to_date(开始日期||' '||开始时间,'yyyy-mm-dd hh24:mi:ss')+时长/86400 结束时间 
      from table TB1;