zoukankan      html  css  js  c++  java
  • oracle to_date

    to_date如何取得毫秒?

    由于oracle中date类型只支持到秒,不支持到毫秒,所以to_date()不能取到毫秒。
    如果要取到毫秒,oracle 9i以上版本,可以使用timestamp类型,是date的扩展类型,能支持到毫秒,毫秒的显示精度是6位,不过有效位是3位,即最大值达到999,满1000ms就进为1s。而与to_date()对应的转换函数可以使用to_timestamp()。
    select to_timestamp('2011-12-15 10:40:10.345', 'yyyy-MM-dd HH24:MI:ss.ff') as mydate from dual;

    如果想将timestamp又转换成date类型,可以使用cast()函数,但得到的date类型没有了毫秒值
    。如下:

    select cast(to_timestamp('2011-12-15 10:40:10.345', 'yyyy-MM-dd HH24:MI:ss.ff') as date) as mydate from dual;



    如把"1970-01-0100:00:00.356“,转化成时间,需要保留毫秒数,怎么做?我一般都是用到秒的(to_date('1970-01-0100:00:00.356','yyyy-mm-dd hh24:mi:ss'))。 毫秒怎么表示啊,请指点!

    9i以上版本
    -----------------------------
    SQL>select to_char(systimestamp,'yyyy-mm-ddhh24:mi:ssxff') time1,
    to_char(current_timestamp) time2 from dual;

    TIME1                     TIME2
    ---------------------------------------------------------------------------------------------
    2003-10-24 10:48:45.656000 24-OCT-03 10.48.45.656000 AM+08:00
    可以看到,毫秒在to_char中对应的是FF。

    SQL> select to_timestamp('2003-10-2410:48:45.656000','yyyy-mm-dd hh24:mi:ssxff') from dual;

    TO_TIMESTAMP('2003-10-2410:48:
    -------------------------------------------------
    24-10月-03 10.48.45.656000000 上午

    还值得一提的是:毫秒的显示精度是6位,不过有效位是3位,即最大值达到999,满1000ms就进为1s

    date类型只能到秒
    用timestamp可以到毫秒


    select to_char(systimestamp, 'yyyy-mm-dd hh24:mi:ss.ff ') fromdual

  • 相关阅读:
    luogu1196 银河英雄传说 (并查集)
    [BZOJ2243][SDOI2011]染色
    [BZOJ1879] [Sdoi2009]Bill的挑战
    [Noip2003] 侦探推理
    [Noip2005] 篝火晚会
    [JZOJ100047] 【NOIP2017提高A组模拟7.14】基因变异
    [九省联考2018]一双木棋chess
    [Noip2009] 靶形数独
    [Luogu2737] [USACO4.1]麦香牛块Beef McNuggets
    [BZOJ3109] [cqoi2013]新数独
  • 原文地址:https://www.cnblogs.com/For-her/p/4166332.html
Copyright © 2011-2022 走看看