Analytics Resources: Insights, Best Practices,

Case Studies and More

close
Written by Hemanta Banerjee
on February 13, 2014

The SQL Below generates a date dimension table where the DATE_WID is a chronological key. This is essential for getting the time functions to work in OBIEE.

 

SELECT
n AS Date_ID,
TO_NUMBER(TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'YYYY')||TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'MM') ||TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'DD')) as DayNum,
TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day') AS Full_Date,
TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'DD') AS Days,
TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'DAY') AS Day_Name,
'WEEK-'||TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'WW') AS Week_Num_Of_Month,
TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'YYYY')||TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'MM') AS Month_Num,
TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'Mon') AS Month_Short,
TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'Month') AS Month_Long,
TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'YYYY')||TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'Q') AS Quarter_Num,
TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'YYYY')||'-Q' || TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'Q') AS Quarter_Short,
TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'YYYY')||' Quarter ' || TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'Q') AS Quarter_Long,
CASE WHEN TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'Q') in ('1','2') then 'Jan-Jun' else 'Jul-Dec' end as HALF_YEARLY,
TO_CHAR(TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(n,'day'),'YYYY') AS Year,
FROM (
select level n
from dual
connect by level <= 1096
 

You may also like:

Data Modeling Business Intelligence PowerBI

Dimension Specific Aggregation in Power BI

When dealing with facts and measures in any BI tool, you can set the aggregation method (such as sum, count, average etc...

Oracle BI Applications Data Modeling OBIEE 12c

eBusiness Suite and Oracle BI Applications Security

By default, an Oracle Business Intelligence installation is configured with an authentication provider that uses the Ora...

Oracle BI Publisher Data Modeling OBIEE 12c

Scheduling OBIEE Reports with CRON

I recently got a request from a colleague to help them with scheduling some reports for delivery, with the destination b...