【问题标题】:Extract year and month from timestamp(6)从时间戳中提取年份和月份(6)
【发布时间】:2014-09-03 12:22:24
【问题描述】:

我有数据库,我以这种格式插入了时间戳(6): 18-AUG-14 02.49.27.000000000 PM.

我想把它提取到这个:2014-08

它被称为 ISO 8601

【问题讨论】:

    标签: oracle timestamp extract iso8601


    【解决方案1】:

    您需要使用to_char 函数从时间戳中提取年月。

    select to_char(timestamp, 'yyyy-mm') from your_table
    

    【讨论】:

      【解决方案2】:

      我是这样做的-

      select extract(year from timestmp) || '-' || extract(month from timestmp) from texmp1;
      

      希望这会有所帮助。

      这是表结构:

          create table texmp1 
      (
      timestmp timestamp
      );
      

      【讨论】:

      • 那将是 2014-8,而不是 2014-08。
      • 对不起,也许我把“extract”这个词弄糊涂了......@KimBergHansen 是对的,它不是 ISO 格式
      猜你喜欢
      • 2018-06-20
      • 1970-01-01
      • 2020-12-24
      • 2015-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      相关资源
      最近更新 更多