Home > Database > Mysql Tutorial > body text

在Oracle中使用from_tz时避免夏令时造成的异常

WBOY
Release: 2016-06-07 16:59:28
Original
1333 people have browsed it

Oracle 中的from_tz函数,可以将一个timstamp和timzone拼成一个timestamp with timezoneSql代码 SQLgt; select from_tz(to_time

Oracle 中的from_tz函数,可以将一个timstamp和timzone拼成一个timestamp with timezone

Sql代码

  •    
  • FROM_TZ(TO_TIMESTAMP('20090102  
  • SQL> select from_tz(to_timestamp('20090102','YYYYMMDD'), 'America/Sao_Paulo') from dual; FROM_TZ(TO_TIMESTAMP('20090102 -------------------------------------------------------------------------------- 02-1月 -09 12.00.00.000000000 上午 AMERICA/SAO_PAULO

     

    但如果这个timestamp在指定的时区内不存在(比如由于夏令时,时钟往前拨了一个小时),就会抛Exception

    Sql代码

  •    
  •    
  • ORA-01878: 在日期时间或间隔中没有找到指定的字段  
  • SQL> select from_tz(to_timestamp('20091101','YYYYMMDD'), 'America/Sao_Paulo') from dual; select from_tz(to_timestamp('20091101','YYYYMMDD'), 'America/Sao_Paulo') from dual ORA-01878: 在日期时间或间隔中没有找到指定的字段

     解决办法嘛,,先取出时区的offset,用其构建好timestamp with timezone后再转回指定的时区就好了

    Sql代码

  •    
  • FROM_TZ(TO_TIMESTAMP('20091101  
  • linux

  • source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!