【问题标题】:How to generate timeseries data into table in Oracle PL/SQL between two date using interval 1 minute?如何使用间隔 1 分钟在两个日期之间将时间序列数据生成到 Oracle PL/SQL 中的表中?
【发布时间】:2018-07-26 12:44:51
【问题描述】:

我是这个话题的新手。在我的设置中,Oracle 12c 标准版数据库和 PL/SQL Developer。

我有一个具有以下结构的表:

int id; 
timestamp time_mon;
double price; 

我需要将数据插入到一个表中,该表生成的时间段为 02.01.2018 00:00 - 02.01.2019 00:00,间隔为 5 分钟。我无法应付这项任务。请帮助我并显示 SQL 代码示例。

【问题讨论】:

    标签: oracle plsql oracle-sqldeveloper oracle12c plsqldeveloper


    【解决方案1】:

    假设您的意思是 02.01.2018 = 1 月 2 日,这可能是一种方式:

    insert into yourTable(id, time_mon, price)
    select ??? as id,                                                      -- to be completed
           date '2018-01-02' + interval '5' minute * (level -1) as time_mon,
           ??? as price                                                    -- to be completed
    from dual
    connect by date '2018-01-02' + interval '5' minute * (level -1) <= date '2019-01-02'
    

    【讨论】:

    • 您只需要添加插入部分,刚刚显示。关于 id 和 price,您需要知道需要插入哪些值
    猜你喜欢
    • 2016-11-23
    • 2012-07-23
    • 2020-07-06
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    相关资源
    最近更新 更多