我的原始问题是有一个格林尼治时间的时间戳1196970334,要转化成本地时间的小时数字,我的转化方法是mod((1196970334+28800)/3600,24),但是我觉得效率会不好,是否有函数直接将1196970334转化成日期类型,然后再取HH24呢?或者直接得到小时数?请大家帮助研究一下。条条大路通罗马!

解决方案 »

  1.   

    select to_char(scn_to_timestamp('4335118084'),'hh24') from dual;
    可以取得系统时。10g有效timestamp_to_scn(sysdate)就是系统时间戳了
      

  2.   

    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining optionsSQL> select to_char(scn_to_timestamp('4335118084'),'hh24') from dual;
    select to_char(scn_to_timestamp('4335118084'),'hh24') from dual
                   *
    第 1 行出现错误:
    ORA-08181: 指定的编号不是有效的系统更改号
    ORA-06512: 在 "SYS.SCN_TO_TIMESTAMP", line 1
    ORA-06512: 在 line 1
      

  3.   

    此类转换需要依赖于数据库内部的数据记录,对于持久的SCN则不能转换,示例如下: 
    SQL> select min(FIRST_CHANGE#) scn,max(FIRST_CHANGE#) scn from v$archived_log;SCN SCN
    ------------------ ------------------
    8907349093953 8908393582271SQL> select scn_to_timestamp(8907349093953) scn from dual;
    select scn_to_timestamp(8907349093953) scn from dual
    *
    ERROR at line 1:
    ORA-08181: specified number is not a valid system change number
    ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1
    ORA-06512: at line 1
    SQL> select scn_to_timestamp(8908393582271) scn from dual;SCN
    --------------------------------------------------------
    05-JAN-07 11.45.50.000000000 AM
     网上搜索来的,我正在研究
      

  4.   

    我研究下来,觉得结果应该是这样,实际时间戳的转换是基于oracle里内部的一个对时间戳的纪录集
    也就是说如果你的数据库里有个时间戳的纪录,就能转换,没有就转换不了
      

  5.   

    对,我感觉这个东西与update或者insert是有关系的,系统改变了才会有scn。
    好像解决不了我的问题。