473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to do Incremental Load using PL/SQL

Hi Guys,

Can you give me some examples for Incremental load in PL/SQL for Datawarehouse projects.

Regards,
Balu
Jul 21 '07 #1
5 13802
debasisdas
8,127 Expert 4TB
Hi
orabalu
Welcome to TSDN.

You have reached the right place for knowledge shairing.

Here you will find a vast resource of related topics and code.

Feel free to post more doubts/questions in the forum.

But before that give a try from your side and if possible try to post what/how you have approached to solve the problem.

It will help Experts in the forum in solving/underestanding your problem in a better way.

Please follow the posting guidelines in every new post/reply.

Please specify your post/question clearly.

Dont expect others to guess and solve your problem.

Regards

Debasis
Jul 23 '07 #2
Hi,

There are some better and effective way to achieve Incremental Data Load using PL/SQL (if you have control over your sources)...
# Create the similar schema as in Source (that means if source has 100 tables that is going to be used to populate target, create similar table structures in this replica schema...you should add some audit columns into this new replica schema like: DML_Flag, Processed_Flag...etc.)
# This replica schema can be kept near by your data warehouse schema.
# Create After Insert/After Update Triggers on all the source tables, this will not affect your source system performance.
# This After Insert/After Update Triggers will push all the newly inserted record and updated record to the Replica Schema.
# Mark DML_Flag as 'I' for Insert records; 'U' for updated records; 'D' for deleted records (it can be a soft delete).
# Now based on the DML_Flag, take the record from this Replica Schema one-by-one.
# First take Insert records then Update and Delete etc.
# Update 'Processed_Flag' column to 'P' ('P' for processed) for corresponding table of Replica Schema simultaneously.
# You can do the Error Handling and Erroneous Data Handling here (if required I can discuss the error_log and erroneous data log mechanism as well using PL/SQL in a separate session)
# Please note that if you are doing error handling and erroneous data handling here, then you should mark even erroneous records too as 'P-Processed'. It is given that you fix the error, based on your error_log, directly into the Source system.....

Hope it certaily help you.

Thanks and Regards,
Ranjeet
Sep 21 '09 #3
tabla
8
Hi Balu,
You can use merge statement where u can put a Flag for new updated or inserted records and maintain track of updated records using trigger in history table.

Warm regards,
Tabla
Sep 24 '09 #4
Dear Tabla,

Could you please elaborate that how can you use merge for incremental data load... it will be really of great help if you can give one example that how to use the suggested update or insert flag while using merge...

thanks and rgds,
ranjeet
Sep 25 '09 #5
tabla
8
Hi balu,
Kindly find the example.
In step 1) Create tables --> the target table for incremental load(MERGE_TEST ) and one for history(MERGE_TEST_HIS)

Step 2) Create trigger to store data which will updat in next day load but already present in table.

step 3) In this cursor will have current data to be loaded. The merge statement will check whether the part_id from cursor is available or not if yes it will update the changes in MERGE_TEST tables and maintains history in MERGE_TEST_HIS table. If the current cursor is totally new then it will insert the as it is. The flag = Y in MERGE_TEST table will indicate that this records are updated and and trans_Date will give on which day load these records are updated.

step 4) select * from merge_Test; will give you total records with current history from the loading has started.

select * from MERGE_TEST_HIS will give the OLD value of updated records with trans_Date on which these records are loaded in MERGE_TEST.

/******step 1)*******************************/
CREATE TABLE MERGE_TEST
as
select /*+parallel(a 10)*/PART_ID, DATE_OF_BIRTH, SURNAME , sysdate trans_Date
From cp_partners a
where part_id > 3623099 and part_id < 3623200

alter table MERGE_TEST add flag varchar2(10);

create table MERGE_TEST_his as select * from MERGE_TEST where 1=2

/******step 2)*******************************/

create or replace trigger merge_Test_trig
AFTER update or delete on merge_test for each row
begin
if (:old.part_Id = :new.part_id) or (:old.DATE_OF_BIRTH <> :new.DATE_OF_BIRTH) or (:old.SURNAME <> :new.SURNAME)
then
insert into merge_test_his
values (:old.part_Id ,:old.DATE_OF_BIRTH ,:old.SURNAME,null,sysdate);
else
null;
end if;
end;

/******step 3)*******************************/

declare
cursor c1 is
select a.PART_ID, sysdate DATE_OF_BIRTH, a.SURNAME
from (select *
From cp_partners
where (part_id > 3623099 and part_id < 3623200)
or (part_id > 3623200 and part_id < 3623300)) a,(select * from MERGE_TEST) b
where a.part_id = b.part_id (+) ;

begin
for z in c1 loop
merge into MERGE_TEST
using dual
on (part_id =z.part_id)
when matched then
update
set DATE_OF_BIRTH = z.date_of_birth,flag = 'Y',trans_Date = sysdate+1
when not matched then
insert (PART_ID, DATE_OF_BIRTH, SURNAME,trans_Date)
values (z.PART_ID, z.DATE_OF_BIRTH, z.SURNAME, sysdate+1);

end loop;
end;

/******step 4)*******************************/
select * from merge_Test;

select * from merge_test_his;

Regards
Tabla
Sep 26 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: g pavlov | last post by:
W3C recommendations notwithstanding (see http://w3.org/TR/html401/appendix/notes.html#notes-tables) I can't seem to persuade either of the leading browsers to do true incremental table loading....
4
by: Xela | last post by:
Hi I am facing the following problem. I load a fact table with around 25 millons lines, and 7 indexes. I load it with 3 million line subsets. I am on a quadriprocessor Solaris machine. The...
3
by: apple | last post by:
UDB v8 fp 6a on AIX 5.1.0.0 Below is a manual incremental recover from compressed backup datasets. With external compress backup datasets, can it be coded to do an automatic incremental recover?...
0
by: Willem | last post by:
Based on MK's TSI_SOON (http://www.trigeminal.com/)I've created a nifty little procedure that - whenever you compact you db you get an incremental backup copy. Given that you have a table with...
4
by: Thorsten Ottosen | last post by:
Dear all, I work on a major system written in C# in visual studio 2003. Our solution has 10+ projects and all projects are compiled with /incremental. In a C++ world, non-incremental builds...
3
by: Alex Shturm | last post by:
Hi, I am trying to activate incremental link using VC7 (.NET 2003) on a pretty big project (executable size is more than 100Mb, and it gets linked from several dozen of libraries and object...
5
by: Joel Matthew | last post by:
My boss was asking about incremental backups. I was scratching my head, thinking that the transaction log and a backup policy (script) for each record set (sorry about the archaic terminology)...
6
by: Raj | last post by:
How can we do an online restore of a tablespace using the incremental backup's? we are on a partitioned database... Also, how could we use backup copy made by the load (using the copy to option...
35
by: mwelsh1118 | last post by:
Why doesn't C# allow incremental compilation like Java? Specifically, in Java I can compile single .java files in isolation. The resulting individual .class files can be grouped into .jar files....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.