程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> Oracle和Vertica中構造日歷數據

Oracle和Vertica中構造日歷數據

編輯:Oracle教程

Vertica裡面構造日歷用法:
SELECT to_number(TO_CHAR(ts::DATE,'yyyymmdd')) as day_id,
year(ts::DATE) as year_of_calendar,
month(ts::DATE) as month_of_year,
dayofweek(ts::DATE) as day_of_week
FROM (
SELECT '01-01-2013'::TIMESTAMP as tm
UNION
SELECT '12-31-2500'::TIMESTAMP as tm
) as t
TIMESERIES ts as '1 Day' OVER (ORDER BY tm);

Oracle裡面構造日歷用法:
select to_date('20130101', 'yyyymmdd') + (level-1) as day_id,
EXTRACT(YEAR FROM (to_date('20130101', 'yyyymmdd') + (level-1))) as year_of_calendar,
EXTRACT(MONTH FROM (to_date('20130101', 'yyyymmdd') + (level-1))) as month_of_year,
--EXTRACT(DAY FROM (to_date('20130101', 'yyyymmdd') + (level-1)) ) as daynum,
to_char(to_date('20130101', 'yyyymmdd') + (level-1), 'D') as dayofweek
from dual
connect by level <= to_date('25001231', 'yyyymmdd') -
to_date('20130101', 'yyyymmdd')

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved