Best practise to detect changes between two tables
Hi,
I try to write a query, that shows me the differences between a table in my DWH and the table in the source system. It should show me new, deleted and updated rows.
My approach is to do a full outer join based on the key and then check if any of the columns changed (source.A!=DWH.A or Source.B!=DWH.B, etc.) to get the updated rows.
My problem is now that my table has millions of rows und more than 100 columns (number, nvarchar, etc.). So the query takes hours.
Is there any best practise solution to optimize that query, by rewriting it, setting indexes or using hash code? I played around with hash code, but it wasn't really faster.
(BTW: CDC, etc are not allowed)
Thanks for any ideas!
890408 wrote:
So i guess I can't use the merge statement, as it is just for SCD1.
Yes you can:
create table products(
name varchar2(20),
price number,
effective_from date,
effective_to date,
active number
insert
into products
values(
'Samuel Adams, 6-pack',
6.99,
null,
sysdate - 51,
0
insert
into products
values(
'Samuel Adams, 6-pack',
7.29,
sysdate - 50,
null,
1
create table product_updates(
name varchar2(20),
price number
insert
into product_updates
values(
'Samuel Adams, 6-pack',
7.49
insert
into product_updates
values(
'Corona, 6-pack',
6.49
select *
from products
NAME PRICE EFFECTIVE EFFECTIVE ACTIVE
Samuel Adams, 6-pack 6.99 13-OCT-11 0
Samuel Adams, 6-pack 7.29 14-OCT-11 1
select *
from product_updates
NAME PRICE
Samuel Adams, 6-pack 7.49
Corona, 6-pack 6.49
merge
into products p
using (
select name,
price,
'update' flag
from product_updates
union all
select chr(0) || name name,
price,
'insert' flag
from product_updates
) u
on (
p.name = u.name
when matched
then update
set effective_to = sysdate,
active = 0
where active = 1
when not matched
then insert
values(
substr(u.name,2),
u.price,
sysdate,
null,
1
where flag = 'insert'
3 rows merged.
select *
from products
NAME PRICE EFFECTIVE EFFECTIVE ACTIVE
Samuel Adams, 6-pack 6.99 13-OCT-11 0
Samuel Adams, 6-pack 7.29 14-OCT-11 03-DEC-11 0
Samuel Adams, 6-pack 7.49 03-DEC-11 1
Corona, 6-pack 6.49 03-DEC-11 1
SQL> SY.
SY.
Similar Messages
-
Synchronising field changes between two table
Hi guys,
I have a requirement were i need to use a field from one table (tableA) to update a field on another table (tableB). Everytime the field changes on tableA it should immediately also change on tableB. How do i go about doing this?
thankshi mukund, thanks for your help, i have attached the full details of the requirement. I think i will use an exit in T-Code "PRMS" to update the relevan field in the tableB. the problem is that this scenario will only work if the field in tableA only gets updated via one transaction(PRMS).
Kindly note that there is a requirement to write a program for Company code 500 which will be able to achieve the following:
To populate the field Previous Account number (LFB1-ALTKN) in the Employee Vendor master data T-code FK02 with data in the Sub-area field (BTRTL) in T-code PRMS.
Furthermore, whenever there is a change in Sub-area field (BTRTL), it should be able to automatically update the Previous Account number (LFB1-ALTKN) in the Employee Vendor master data with the change to enable up to date information which will be required by payroll when processing payment via the Automatic payment program in FI.
There is already a program RPRAPA00 which is working on the similar basis and so can be referred to it.
Please feel free to ask me for any further information. -
Need to find the Difference between two table
Hello ,
I have stucked in program as below scenario:-
I have two tables of huge data of same structure in a same schema.I need to find the difference exact values in tables.
By using MINUS we can find the difference between two table ,i need to find the what exact difference in the there values with colunm and value at that column.
Example TableA
Col1 col2 col3 col4 col5.... col50
10 ABC 2001 EE 444 TT
40 XYZ 3002 RR 445 TT3
80 DEF 6005 YY 446 YY8
TableB
Col1 col2 col3 col4 col5.... col50
10 ABC 2001 EE 444 TT
40 XYZ 3002 RR 445 TT3
81 DEF 6005 Yu 447 YY8
I need to the out put like this :-
The Diffence between two table is
TableA.COL1=80 TableB.Col1=81, Different
TableA.Col4=YY TableB.col4=Yu,Different
TableA.Col5=446TableB.col5=447,Different
Please suggest me to write the pl/sql program for the same
thanx in advance
KKThanx friends for all your efforts
I have a sample code for the same,this will compare the two tables for single row in each table .
what r the modification needed for the multiple rows of values in the two tables??
Please suggest!!
CREATE OR REPLACE PROCEDURE test_compare
IS
TYPE t_col
IS
TABLE OF VARCHAR2 (30)
INDEX BY PLS_INTEGER;
l_col t_col;
j NUMBER := 0;
l_sql VARCHAR2 (2000);
col1 VARCHAR2 (30);
col2 VARCHAR2 (30);
val1 NUMBER;
val2 NUMBER;
status VARCHAR2 (30);
CURSOR c1
IS
SELECT column_id, column_name
FROM all_tab_columns
WHERE table_name = 'TEST1';
BEGIN
FOR i IN c1
LOOP
j := j + 1;
l_col (j) := i.column_name;
END LOOP;
FOR k IN 1 .. j
LOOP
l_sql :=
'SELECT '
|| ''''
|| l_col (k)
|| ''''
|| ', '
|| 'TEST2.'
|| l_col (k)
|| ', '
|| ''''
|| l_col (k)
|| ''''
|| ', '
|| 'TEST1.'
|| l_col (k )
|| ', '
|| 'DECODE(TEST2.'
|| l_col (k)
|| ' -TEST1.'
|| l_col (k)
|| ', 0, ''NO CHANGE'', ''CHANGED'') FROM TEST2, TEST1';
EXECUTE IMMEDIATE l_sql INTO col1, val1,col2, val2, status;
IF status = 'CHANGED'
THEN
DBMS_OUTPUT.put_line( 'TEST2.'
|| col1
|| '='
|| val1
|| ', TEST1.'
|| col2
|| '='
|| val2
|| ', '
|| status);
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Error:- ' || SQLERRM);
END;
/ -
How to compare data between two tables?
Hi,
My team is trying to develop a SAP data migration tool (DMT) using ABAP.
One of the functionalities in the DMT is to validate the data in the staging area against the loaded SAP data.
The tables in the stagin area are customer tables (i.e. user-defined tables starting with Y, Z).
How do I compare the data in the staging area against data that are loaded into SAP tables? Are there some built-in SAP functions to do this? Or, are there some better ways of doing this (e.g. instead of comparing against data in the SAP tables, we compare with some INTERNAL tables)?
Any help would be greatly appreciated, thanks!Hi Kian,
Use <b>SCMP</b> transaction to compare data between two tables and you can not use this for comparing internal tables.
Thanks,
Vinay -
How to find the structural difference between two tables
Hi all,
How to find the structural difference between two tables .
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
Thanks,
P Prakashyou could try something similar to this, for each table pair that you want to compare:
SELECT 'TABLE_A has these columns that are not in TABLE_B', DIFF.*
FROM (
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_A'
MINUS
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_B'
) DIFF
UNION
SELECT 'TABLE_B has these columns that are not in TABLE_A', DIFF.*
FROM (
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_B'
MINUS
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_A'
) DIFF;that's assuming, column_name, data_type and data_length are all you want to compare on. -
How to write select statement between two tables
hi,
i need to do comparision between two table for each records.ex:
table1:
regid regno ind
1 1001
1 1002
1 1003
1 1004
and table2:
regid regno
1 1002
1 1005
i need to select first row from table and loop for values in second table, if the values found first record , the record must update 'yes' to ind, if not 'No'.
please help with this.
thanks in advance
rajaHi Raja,
Do it like this. loop the first table and read the second table.
Use where condition to satisfy the conditions.
Or
In your select query use joins. Like this.
SELECT mara~matnr
marc~werks
INTO TABLE t_material
FROM mara AS mara INNER JOIN marc AS marc
ON maramatnr = marcmatnr
WHERE mara~mtart = p_mtart.
Instead of MARA and MARC here use your tables.
Much Regards,
Amuktha. -
I need to implement Drag N Drop between two tables which saves both records
I need to implement Drag N Drop between two tables which saves both records in a third page, by using drag n drop.
check this video http://baigsorcl.blogspot.com/2011/01/drag-and-drop-collection-in-oracle-adf.html
-
How to build "Greater/less or Equal" relationships between two tables?
Hi,
Is there any straightforward approachs to realize the following kind of relationships between two tables?
Table1.process_end_date >= Table2.work_start_date and
Table1.process_end_date <= Table2.work_end_date
BTW, there's no common columns for these two tables to do simple joins (inner, outter...).
Thanks.
Regards,
QilongSure.
Table.SelectRows filters a given table (in this case Table2) based on a function provided as the second argument.
(table2Row) => is the start of our filter function. It defines a function that takes one argument, called table2Row. Each row of Table2 will be passed to this function. If the function returns true, the row will be kept. If the function returns false,
the row will be filtered out.
The right hand side of the => is the filter expression. Because we're adding the custom column to Table1, we can reference a field in the current row of Table1 using square brackets (e.g. [process_end_date]). To reference the fields in the current row
of Table2, we have to index into the table2Row variable passed to our function (e.g. table2Row[work_start_date]).
Hope that helps.
Ehren -
Query the data between two tables
Need help for query the data between two tables
Table 1: Time sheet
P.ID P.Name EmpID HoursSpend DateTime
c12234 Test 25 4 06/12/2013
c12234 Test 25 7 06/13/2013
c12234 Test 25 8 06/15/2013
c12234 Test 5 3 06/21/2013
c12234 Test 2 5 07/15/2013
c12234 Test 25 4 07/21/2013
Table 2: cost table
EmpID FromDate ToDate Rate
25 05/01/2013 06/30/2013 250
2 04/01/2013 05/31/2013 150
25 07/01/2013 09/30/2013 300
Output
P.ID P.Name EmpID HoursSpend DateTime Rate Total (HoursSond x Rate)
c12234 Test 25 4 06/12/2013 250 1000 (4*250)
c12234 Test 25 7 06/13/2013 250 1750
c12234 Test 25 8 06/15/2013 250
2000
c12234 Test 25 4 07/21/2013 300
1200
c12234 Test 2 5 07/15/2013 150
750
===========================================
Total 28
6700
============================================
Here EmpID =2 don't have rate in the cost table on july month should be pick from last entry from cost table.Hi Gopal,
According to your description, it seems that the output needn’t include the row when EmpID=2. Because the DateTime for it in Table1 doesn’t included between FromDate column and ToDate column. After testing the issue in my environment, we can refer to the
query like below to achieve your requirement:
SELECT time.*,cost.EmpID,cost.Rate,(time.HoursSpend * cost.Rate)as [Total (HoursSond x Rate)]
FROM [Time sheet] as time
INNER JOIN
[cost table]as cost
ON time.EmpID = cost.EmpID
AND time.DateTime BETWEEN cost.FromDate AND cost.ToDate
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Subject: How to do join between two tables using something like SE16
SE16, SE11 provide form based interface query information from a single table. Is there a way to do join between two tables without creating an infoset erc? I am looking for something similar to sql join but in SAP BI 7.0
Thanks.Hi
Pls look into below links. Hope this helps you.
1. http://help.sap.com/saphelp_46c/helpdata/EN/d2/cb45bf455611d189710000e8322d00/content.htm
2. http://help.sap.com/saphelp_46c/helpdata/EN/d2/cb45a5455611d189710000e8322d00/content.htm
Regards
Sirigiri -
How to give relationship between two tables with comon column with between oprator
Hi Folks,
I am using Sql Server 2008R2. I am getting a problem to establish relationship between two tables.
I have two Tables, 1.Inventory Details Table another one is Inventory Header Table.
Inventory Details Table having a column Card No and inventory Header Table having columns From card No and To Card No.
I want to give relationship between these two tables with Card no. Could you please provide me the Sql Query.
Your help would be greatly appreciated .
Regards
hasthi.
email:[email protected]Hi Raju,
We have two way that we can relate to the table either join or quality condition use following syntax/Query for relating two tables
select * from Inventory_Details ID inner join Inventory_Header IH on ID.CardNo between IH.FrmCardno and IH.ToCardNo
or
Select * from Inventory_Details ID ,Inventory_Header IH where ID.CardNo=IH.CardNo OrSelect * from Inventory_Details ID ,Inventory_Header IH where ID.CardNo between IH.FrmCardno and IH.ToCardNo
Hope this will help you
Niraj Sevalkar -
How to check relation between two tables in same database
How to check relation between two tables in same database using Oracle SQL developer. Version 2.1.1.64
Hi,
Try this,
SELECT cons.owner AS child_owner, cons.table_name AS child_table,
cons.constraint_name constaint_name,
cons.constraint_type constraint_type, col.owner parent_owner,
col.table_name parent_table, col.column_name column_name
FROM dba_cons_columns col, dba_constraints cons
WHERE cons.r_owner = col.owner
AND cons.r_constraint_name = col.constraint_name
AND col.owner = 'MY_USER'
ORDER BY child_table;Thanks,
Shankar -
Relationship between two tables
Hi,
Can some one tell me how can i find the relationship between two tables in CRM. is there any transaction for the same. Is it possible to see the data model.
Thanks
Akila.RHi Nishant ,
Could you please explain brief about the Data relationship ......??
I can see the Foreign Key & Check Table relation in se11 .
Since I am in the Analysing phase ,
what are all the details can i get from Foreign Key & Check table kind relations ...??
Thanks
Rgds
Ganesh -
Transaction to see common data between two tables
Is there any transaction to see common data between two tables with out creating views.
what is the transaction to see the link between two tables
regards
pavanHi,
Go to a transparent table for which you want to know the common fields, from there click the button GRAPHICS (shortcut Ctrl + Shift + F11) in the application tool bar. Then you are redirected to a list containing the tables belonging to the same group. There select whatever tables you would like to see and click COPY. A window will pop-up and will show the relationship between the fields of the tables in a flow chart format.
see to this link also.
Common fields b/w tables
Regards,
Revathi Bhoopal. -
How to implement Master - Detail relation between two table views in OBI11g
Hi Gurus,
I was able to create master- detail between table and graph.
But between two tables not.
I put the listening column on the table prompt and specified channel for the Listen to Master-Detail Events in the table properties.
But did not work.
Where is the mistake?
I"d appreciate any ideas, help!
Thanks
LaszloThanks for the link!
My question is :
Are the same thinga the page edge and table prompt for the tables?
If not how to add a column to the page edge (not to the table prompt)?
Thanks
Laszlo
Maybe you are looking for
-
HP ProBook 4530s won't power up
Hi, When I power up the HP ProBook 4530s the power button lights up but the display doesn't come on. It stays that way untilI power the notebook down (nothing is displayed whatover). The battery is in useless condition and the notebook runs on AC po
-
Every time I open the app store on my iPod touch, it says 'too many http redirects' whenever I click on the Categories and Top 25 tabs. I tried force quitting the app store, that didn't work. I tried closing all windows in Safari and force quitting s
-
Clear wsdl cache every time a bpel process call is made.
Hi All, I have a bpel process which gets input xml of the size of 6MB. This bpel process interacts with a java component using the WSIF approach to reorder the xml input recieved. The strange problem that i am currently encountering right now is for
-
Oracle Instant Client is a memory hog?
Hi all, I am having (potentially) an issue that I need to confirm with folks out there. I am not a DBA - I have a decent understanding of SQL and have been exposed to several RDBMS's, but this is my first time developing in PHP specifically with Orac
-
Audio from flv player won't stop playing
Hi, I have a swf loading in another swf that has a video player in it. When I remove the swf from the stage, the swf goes away but the audio from the swf keeps playing. Is there a way to tell that swf to stop playing from the parent swf?