SlideShare a Scribd company logo
Recipes of Data Warehouse and
Business Intelligence

Staging Area: How to verify the reference day of the
data source
The Micro ETL Foundation
•

•

•

•
•

The Micro ETL Foundation is a set of ideas and solutions for Data Warehouse and
Business Intelligence Projects in Oracle environment.
It doesn’t use expensive ETL tools, but only your intelligence and ability to
think, configure, build and load data using the features and the programming
language of your RDBMS.
This recipes is another easy example based on the slides of Recipes 1 and 2 of Data
Warehouse and Business Intelligence.
Copying the content of the following slides with your editor and SQL Interface
utility, you can reproduce this example.
The solution presented here is the check of the reference day of a data source.
This is another little component to permit us to achive the complete control of the
Staging Area loading.
The problem
• In the «Recipe 3» we have seen the check about the rows number. We
have ensured this: You have received, for example, 943 rows from the data
source file. You have loaded 943 rows in the Staging Area table.
• This is not enough.
• Now we need to ensure that the reference day (DAY_KEY) of the data is
correct.
• Suppose that you start the loading of account balances file now:
wednesday at 01:00. You expect that the reference day of the balances is
yesterday, tuesday. The loading day is today, the expected day is today-1.
• If now is monday, and there is no process during week-end, the expected
day is today-3, friday
What to check
• At the end of the loading, we need to control that it is gone all ok. We
need to ensure that in this loading day, the expected day is correct. To
have this safety, we must:
1. Build a configuration table.
2. Initialize the configuration table with the expected day for every
loading day
3. Create a log table
4. Fill the log table at the end of the load of Staging Area.
• Without this check we risk to reload the same day if the source system
had some problems or it has not been able to overwrite the previous file.
The daily configuration table
•
•
•
•
•

•

•

IO_COD is the same of the configuration
table created in «Recipes2». It is unique.
DAY_KEY is the loading day.
DY_TXT is the day of the week
WD_FLG is the flag of working day.
FROM_EDAY_KEY/TO_EDAY_KEY are the
expected range of day. For daily data
source file they will have the same value.
To have a range can be useful for
monthly data files that contains all the
days of the month.
Now we see how to configure 3 years.

DROP TABLE STA_IODAY_CFT;
CREATE TABLE STA_IODAY_CFT
(
IO_COD
VARCHAR2(12),
DAY_KEY
NUMBER,
DY_TXT
VARCHAR2(3),
WD_FLG
NUMBER,
FROM_EDAY_KEY NUMBER,
TO_EDAY_KEY NUMBER
);
The load of daily table
•
•
•

The load of this table may be done only one time.
In this example we configure a daily loading (excluding week-end) from a year in
the future (sysdate+365) and 2 years in the past.
Configure holidays according to your country calendar. Here are configured only
Christmas Day, New Year's Day and Independence Day.

INSERT INTO STA_IODAY_CFT (IO_COD,DAY_KEY,DY_TXT,WD_FLG,FROM_EDAY_KEY,TO_EDAY_KEY)
WITH X AS (
SELECT TO_CHAR((SYSDATE+365)-LEVEL,'YYYYMMDD') AS DAY_KEY
,TO_CHAR((SYSDATE+365)-LEVEL,'dy') DY_TXT
FROM DUAL CONNECT BY LEVEL <= (365*3))
,Y AS (
SELECT TO_CHAR((SYSDATE+365)-LEVEL,'YYYYMMDD') AS DAY_KEY
,FIRST_VALUE(TO_CHAR((SYSDATE+365)-LEVEL,'YYYYMMDD'))
OVER (ORDER BY TO_CHAR((SYSDATE+365)-LEVEL,'YYYYMMDD')
ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS EDAY_KEY
FROM DUAL
WHERE TO_CHAR((SYSDATE+365)-LEVEL,'dy') NOT IN ('sun','sat')
AND SUBSTR(TO_CHAR(SYSDATE+365-LEVEL,'YYYYMMDD'),5)
NOT IN ('0101','0704','1225')
CONNECT BY LEVEL <= (365*3) ORDER BY 1 DESC)
SELECT 'employees1'
,X.DAY_KEY,X.DY_TXT
,(CASE WHEN (EDAY_KEY IS NULL) THEN 0 ELSE 1 END)
,Y.EDAY_KEY,Y.EDAY_KEY
FROM X
LEFT OUTER JOIN Y ON (X.DAY_KEY=Y.DAY_KEY)
ORDER BY 1,2 DESC;
The daily log table
•
•
•

•

This table must contain a row for
every data source file.
The DAY_KEY is the loading day
The others day columns are the
expected reference day and the
effective reference day.
The RET_COD contains the result
code of the check and will be ‘OK ‘ or
‘NOT OK’.

DROP TABLE STA_IODAY_LOT;
CREATE TABLE STA_IODAY_LOT
(
IO_COD
VARCHAR2(12) NOT NULL,
SOURCE_COD VARCHAR2(80) NOT NULL,
DAY_KEY
NUMBER,
FROM_EDAY_KEY NUMBER,
TO_EDAY_KEY NUMBER,
FROM_DAY_KEY NUMBER,
TO_DAY_KEY NUMBER,
RET_COD
VARCHAR2(30),
STAMP_DTS DATE
);
The load of the log table
•

•
•

We use the test case of the «Recipe 2» and the data loaded into
STA_EMPLOYEES1_STT table. (so it has an old day_key)
We calculate the min and max day_key from the Staging Area table.
We compare the received day(s) with the expected day(s)
INSERT INTO STA_IODAY_LOT (
IO_COD, SOURCE_COD, DAY_KEY,
FROM_EDAY_KEY, TO_EDAY_KEY, FROM_DAY_KEY,
TO_DAY_KEY, RET_COD, STAMP_DTS)
WITH X AS (
SELECT SOURCE_COD
,TO_CHAR(SYSDATE,'YYYYMMDD') DAY_KEY
,MIN(DAY_KEY) FROM_DAY_KEY
,MAX(DAY_KEY) TO_DAY_KEY
FROM STA_EMPLOYEES1_STT
GROUP BY SOURCE_COD)
SELECT A.IO_COD
,X.SOURCE_COD
,X.DAY_KEY
,A.FROM_EDAY_KEY,A.TO_EDAY_KEY
,X.FROM_DAY_KEY,X.TO_DAY_KEY
,(CASE WHEN (A.FROM_EDAY_KEY+A.TO_EDAY_KEY=X.FROM_DAY_KEY+X.TO_DAY_KEY) THEN 'OK' ELSE 'NOT OK' END)
,SYSDATE
FROM STA_IODAY_CFT A
LEFT OUTER JOIN X ON (A.DAY_KEY = X.DAY_KEY)
WHERE A.IO_COD = 'employees1'
AND A.DAY_KEY = TO_CHAR(SYSDATE,'YYYYMMDD');
COMMIT;
Conclusion
We are at the end of this recipe. The configuration and the log tables are:

With only two tables, we have reached the control of the reference day of the source
data without ETL tools.
This is the philosophy of Micro ETL Foundation.
Email - massimo_cenci@yahoo.it
Blog (italian/english) - http://massimocenci.blogspot.it/

More Related Content

PPTX
Data Warehouse and Business Intelligence - Recipe 1
Massimo Cenci
 
PPTX
Data Warehouse and Business Intelligence - Recipe 3
Massimo Cenci
 
PPTX
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
Massimo Cenci
 
PPTX
Data Warehouse and Business Intelligence - Recipe 2
Massimo Cenci
 
PPT
Recipe 14 of Data Warehouse and Business Intelligence - Build a Staging Area ...
Massimo Cenci
 
PPTX
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Massimo Cenci
 
PPTX
Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...
Massimo Cenci
 
PPTX
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...
Massimo Cenci
 
Data Warehouse and Business Intelligence - Recipe 1
Massimo Cenci
 
Data Warehouse and Business Intelligence - Recipe 3
Massimo Cenci
 
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
Massimo Cenci
 
Data Warehouse and Business Intelligence - Recipe 2
Massimo Cenci
 
Recipe 14 of Data Warehouse and Business Intelligence - Build a Staging Area ...
Massimo Cenci
 
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Massimo Cenci
 
Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...
Massimo Cenci
 
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...
Massimo Cenci
 

What's hot (20)

PPTX
Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...
Massimo Cenci
 
PPT
Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)
Massimo Cenci
 
PPTX
Recipe 16 of Data Warehouse and Business Intelligence - The monitoring of the...
Massimo Cenci
 
DOCX
DataBase Management System Lab File
Uttam Singh Chaudhary
 
DOC
Dbms lab Manual
Vivek Kumar Sinha
 
PPTX
Recipes 9 of Data Warehouse and Business Intelligence - Techniques to control...
Massimo Cenci
 
PPTX
New T-SQL Features in SQL Server 2012
Richie Rump
 
PPTX
MySQL Replication Evolution -- Confoo Montreal 2017
Dave Stokes
 
DOCX
Multiple files single target single interface
Dharmaraj Borse
 
PDF
Advanced MySQL Query Optimizations
Dave Stokes
 
PPTX
Getting Started with MySQL I
Sankhya_Analytics
 
PPTX
Oracle Database 12.1.0.2 New Features
Alex Zaballa
 
DOCX
Sql loader good example
Aneel Swarna MBA ,PMP
 
DOCX
Oracle sql loader utility
nageswarareddapps
 
PPTX
T-SQL Overview
Ahmed Elbaz
 
PDF
OER UNIT 4 PARTITION
Girija Muscut
 
PPTX
Oracle Data Redaction
Alex Zaballa
 
DOC
Oracle notes
Prashant Dadmode
 
PDF
Sql introduction
vimal_guru
 
PPTX
Getting Started with MySQL II
Sankhya_Analytics
 
Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...
Massimo Cenci
 
Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)
Massimo Cenci
 
Recipe 16 of Data Warehouse and Business Intelligence - The monitoring of the...
Massimo Cenci
 
DataBase Management System Lab File
Uttam Singh Chaudhary
 
Dbms lab Manual
Vivek Kumar Sinha
 
Recipes 9 of Data Warehouse and Business Intelligence - Techniques to control...
Massimo Cenci
 
New T-SQL Features in SQL Server 2012
Richie Rump
 
MySQL Replication Evolution -- Confoo Montreal 2017
Dave Stokes
 
Multiple files single target single interface
Dharmaraj Borse
 
Advanced MySQL Query Optimizations
Dave Stokes
 
Getting Started with MySQL I
Sankhya_Analytics
 
Oracle Database 12.1.0.2 New Features
Alex Zaballa
 
Sql loader good example
Aneel Swarna MBA ,PMP
 
Oracle sql loader utility
nageswarareddapps
 
T-SQL Overview
Ahmed Elbaz
 
OER UNIT 4 PARTITION
Girija Muscut
 
Oracle Data Redaction
Alex Zaballa
 
Oracle notes
Prashant Dadmode
 
Sql introduction
vimal_guru
 
Getting Started with MySQL II
Sankhya_Analytics
 
Ad

Similar to Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to verify the reference day (20)

PPTX
Do You Have the Time
Michael Antonovich
 
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
PDF
Ebs dba con4696_pdf_4696_0001
jucaab
 
PDF
Oracle SQL Tuning
Alex Zaballa
 
PDF
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
PDF
Oracle SQL Basics
Dhananjay Goel
 
PPTX
SQL Windowing
Sandun Perera
 
PDF
从 Oracle 合并到 my sql npr 实例分析
YUCHENG HU
 
PPTX
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
Dave Stokes
 
PDF
Date dimension table - part II
Dirk Cludts
 
PDF
Avoiding cursors with sql server 2005 tech republic
Kaing Menglieng
 
PDF
Scaling MySQL Strategies for Developers
Jonathan Levin
 
PDF
Open Source 101 2022 - MySQL Indexes and Histograms
Frederic Descamps
 
PPTX
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
PPTX
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
PDF
RivieraJUG - MySQL Indexes and Histograms
Frederic Descamps
 
PPTX
cPanel now supports MySQL 8.0 - My Top Seven Features
Dave Stokes
 
PDF
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
Citus Data
 
PPTX
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
TAISEEREISA
 
Do You Have the Time
Michael Antonovich
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
Ebs dba con4696_pdf_4696_0001
jucaab
 
Oracle SQL Tuning
Alex Zaballa
 
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
Oracle SQL Basics
Dhananjay Goel
 
SQL Windowing
Sandun Perera
 
从 Oracle 合并到 my sql npr 实例分析
YUCHENG HU
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
Dave Stokes
 
Date dimension table - part II
Dirk Cludts
 
Avoiding cursors with sql server 2005 tech republic
Kaing Menglieng
 
Scaling MySQL Strategies for Developers
Jonathan Levin
 
Open Source 101 2022 - MySQL Indexes and Histograms
Frederic Descamps
 
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
RivieraJUG - MySQL Indexes and Histograms
Frederic Descamps
 
cPanel now supports MySQL 8.0 - My Top Seven Features
Dave Stokes
 
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
Citus Data
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
TAISEEREISA
 
Ad

More from Massimo Cenci (16)

PPTX
Il controllo temporale dei data file in staging area
Massimo Cenci
 
PPTX
Tecniche di progettazione della staging area in un processo etl
Massimo Cenci
 
PPTX
Note di Data Warehouse e Business Intelligence - Il giorno di riferimento dei...
Massimo Cenci
 
PPTX
Recipe 12 of Data Warehouse and Business Intelligence - How to identify and c...
Massimo Cenci
 
PPTX
Note di Data Warehouse e Business Intelligence - Pensare "Agile"
Massimo Cenci
 
PPTX
Note di Data Warehouse e Business Intelligence - La gestione delle descrizioni
Massimo Cenci
 
PPTX
Recipes 10 of Data Warehouse and Business Intelligence - The descriptions man...
Massimo Cenci
 
PPTX
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...
Massimo Cenci
 
PPTX
Data Warehouse - What you know about etl process is wrong
Massimo Cenci
 
PPTX
Letter to a programmer
Massimo Cenci
 
PPTX
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...
Massimo Cenci
 
PPTX
Data Warehouse e Business Intelligence in ambiente Oracle - Il sistema di mes...
Massimo Cenci
 
PPTX
Data Warehouse e Business Intelligence in ambiente Oracle - Il sistema di mes...
Massimo Cenci
 
PPT
Oracle All-in-One - how to send mail with attach using oracle pl/sql
Massimo Cenci
 
PPTX
Note di Data Warehouse e Business Intelligence - Le Dimensioni di analisi (pa...
Massimo Cenci
 
PPTX
Note di Data Warehouse e Business Intelligence - Le Dimensioni di analisi
Massimo Cenci
 
Il controllo temporale dei data file in staging area
Massimo Cenci
 
Tecniche di progettazione della staging area in un processo etl
Massimo Cenci
 
Note di Data Warehouse e Business Intelligence - Il giorno di riferimento dei...
Massimo Cenci
 
Recipe 12 of Data Warehouse and Business Intelligence - How to identify and c...
Massimo Cenci
 
Note di Data Warehouse e Business Intelligence - Pensare "Agile"
Massimo Cenci
 
Note di Data Warehouse e Business Intelligence - La gestione delle descrizioni
Massimo Cenci
 
Recipes 10 of Data Warehouse and Business Intelligence - The descriptions man...
Massimo Cenci
 
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...
Massimo Cenci
 
Data Warehouse - What you know about etl process is wrong
Massimo Cenci
 
Letter to a programmer
Massimo Cenci
 
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...
Massimo Cenci
 
Data Warehouse e Business Intelligence in ambiente Oracle - Il sistema di mes...
Massimo Cenci
 
Data Warehouse e Business Intelligence in ambiente Oracle - Il sistema di mes...
Massimo Cenci
 
Oracle All-in-One - how to send mail with attach using oracle pl/sql
Massimo Cenci
 
Note di Data Warehouse e Business Intelligence - Le Dimensioni di analisi (pa...
Massimo Cenci
 
Note di Data Warehouse e Business Intelligence - Le Dimensioni di analisi
Massimo Cenci
 

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
The Future of Artificial Intelligence (AI)
Mukul
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 

Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to verify the reference day

  • 1. Recipes of Data Warehouse and Business Intelligence Staging Area: How to verify the reference day of the data source
  • 2. The Micro ETL Foundation • • • • • The Micro ETL Foundation is a set of ideas and solutions for Data Warehouse and Business Intelligence Projects in Oracle environment. It doesn’t use expensive ETL tools, but only your intelligence and ability to think, configure, build and load data using the features and the programming language of your RDBMS. This recipes is another easy example based on the slides of Recipes 1 and 2 of Data Warehouse and Business Intelligence. Copying the content of the following slides with your editor and SQL Interface utility, you can reproduce this example. The solution presented here is the check of the reference day of a data source. This is another little component to permit us to achive the complete control of the Staging Area loading.
  • 3. The problem • In the «Recipe 3» we have seen the check about the rows number. We have ensured this: You have received, for example, 943 rows from the data source file. You have loaded 943 rows in the Staging Area table. • This is not enough. • Now we need to ensure that the reference day (DAY_KEY) of the data is correct. • Suppose that you start the loading of account balances file now: wednesday at 01:00. You expect that the reference day of the balances is yesterday, tuesday. The loading day is today, the expected day is today-1. • If now is monday, and there is no process during week-end, the expected day is today-3, friday
  • 4. What to check • At the end of the loading, we need to control that it is gone all ok. We need to ensure that in this loading day, the expected day is correct. To have this safety, we must: 1. Build a configuration table. 2. Initialize the configuration table with the expected day for every loading day 3. Create a log table 4. Fill the log table at the end of the load of Staging Area. • Without this check we risk to reload the same day if the source system had some problems or it has not been able to overwrite the previous file.
  • 5. The daily configuration table • • • • • • • IO_COD is the same of the configuration table created in «Recipes2». It is unique. DAY_KEY is the loading day. DY_TXT is the day of the week WD_FLG is the flag of working day. FROM_EDAY_KEY/TO_EDAY_KEY are the expected range of day. For daily data source file they will have the same value. To have a range can be useful for monthly data files that contains all the days of the month. Now we see how to configure 3 years. DROP TABLE STA_IODAY_CFT; CREATE TABLE STA_IODAY_CFT ( IO_COD VARCHAR2(12), DAY_KEY NUMBER, DY_TXT VARCHAR2(3), WD_FLG NUMBER, FROM_EDAY_KEY NUMBER, TO_EDAY_KEY NUMBER );
  • 6. The load of daily table • • • The load of this table may be done only one time. In this example we configure a daily loading (excluding week-end) from a year in the future (sysdate+365) and 2 years in the past. Configure holidays according to your country calendar. Here are configured only Christmas Day, New Year's Day and Independence Day. INSERT INTO STA_IODAY_CFT (IO_COD,DAY_KEY,DY_TXT,WD_FLG,FROM_EDAY_KEY,TO_EDAY_KEY) WITH X AS ( SELECT TO_CHAR((SYSDATE+365)-LEVEL,'YYYYMMDD') AS DAY_KEY ,TO_CHAR((SYSDATE+365)-LEVEL,'dy') DY_TXT FROM DUAL CONNECT BY LEVEL <= (365*3)) ,Y AS ( SELECT TO_CHAR((SYSDATE+365)-LEVEL,'YYYYMMDD') AS DAY_KEY ,FIRST_VALUE(TO_CHAR((SYSDATE+365)-LEVEL,'YYYYMMDD')) OVER (ORDER BY TO_CHAR((SYSDATE+365)-LEVEL,'YYYYMMDD') ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS EDAY_KEY FROM DUAL WHERE TO_CHAR((SYSDATE+365)-LEVEL,'dy') NOT IN ('sun','sat') AND SUBSTR(TO_CHAR(SYSDATE+365-LEVEL,'YYYYMMDD'),5) NOT IN ('0101','0704','1225') CONNECT BY LEVEL <= (365*3) ORDER BY 1 DESC) SELECT 'employees1' ,X.DAY_KEY,X.DY_TXT ,(CASE WHEN (EDAY_KEY IS NULL) THEN 0 ELSE 1 END) ,Y.EDAY_KEY,Y.EDAY_KEY FROM X LEFT OUTER JOIN Y ON (X.DAY_KEY=Y.DAY_KEY) ORDER BY 1,2 DESC;
  • 7. The daily log table • • • • This table must contain a row for every data source file. The DAY_KEY is the loading day The others day columns are the expected reference day and the effective reference day. The RET_COD contains the result code of the check and will be ‘OK ‘ or ‘NOT OK’. DROP TABLE STA_IODAY_LOT; CREATE TABLE STA_IODAY_LOT ( IO_COD VARCHAR2(12) NOT NULL, SOURCE_COD VARCHAR2(80) NOT NULL, DAY_KEY NUMBER, FROM_EDAY_KEY NUMBER, TO_EDAY_KEY NUMBER, FROM_DAY_KEY NUMBER, TO_DAY_KEY NUMBER, RET_COD VARCHAR2(30), STAMP_DTS DATE );
  • 8. The load of the log table • • • We use the test case of the «Recipe 2» and the data loaded into STA_EMPLOYEES1_STT table. (so it has an old day_key) We calculate the min and max day_key from the Staging Area table. We compare the received day(s) with the expected day(s) INSERT INTO STA_IODAY_LOT ( IO_COD, SOURCE_COD, DAY_KEY, FROM_EDAY_KEY, TO_EDAY_KEY, FROM_DAY_KEY, TO_DAY_KEY, RET_COD, STAMP_DTS) WITH X AS ( SELECT SOURCE_COD ,TO_CHAR(SYSDATE,'YYYYMMDD') DAY_KEY ,MIN(DAY_KEY) FROM_DAY_KEY ,MAX(DAY_KEY) TO_DAY_KEY FROM STA_EMPLOYEES1_STT GROUP BY SOURCE_COD) SELECT A.IO_COD ,X.SOURCE_COD ,X.DAY_KEY ,A.FROM_EDAY_KEY,A.TO_EDAY_KEY ,X.FROM_DAY_KEY,X.TO_DAY_KEY ,(CASE WHEN (A.FROM_EDAY_KEY+A.TO_EDAY_KEY=X.FROM_DAY_KEY+X.TO_DAY_KEY) THEN 'OK' ELSE 'NOT OK' END) ,SYSDATE FROM STA_IODAY_CFT A LEFT OUTER JOIN X ON (A.DAY_KEY = X.DAY_KEY) WHERE A.IO_COD = 'employees1' AND A.DAY_KEY = TO_CHAR(SYSDATE,'YYYYMMDD'); COMMIT;
  • 9. Conclusion We are at the end of this recipe. The configuration and the log tables are: With only two tables, we have reached the control of the reference day of the source data without ETL tools. This is the philosophy of Micro ETL Foundation. Email - [email protected] Blog (italian/english) - http://massimocenci.blogspot.it/