Compare Table Data on 2 different databases having same schema
I need to compare data in all the tables in 2 different databases having same schema.
If there is any difference in data in any table on Database1 and Database2 then I need to update/insert/delete the rows in my table in Database2.
So Database1 is my source database and Database2 is my sync database. I cannot use expdp tables as I am not having sufficient privileges to the database server.
Also I cannot drop and recreate the tables as they are huge.
Can anyone please guide me how to compare data and to write a script to comapre the changes in say Database1.Table1 and Database2.Table1 and then accordingly do inserts/updates/deleted on Database2.Table1?
Thanks
Karthick_Arp wrote:
Do you have a DBLink? If youes you can do this.
1. Login into the Database-2 and run this code.
begin
for i in (select table_name from user_tables)
loop
execute immediate 'truncate table ' || i.table_name;
end loop;
end;This will empty all the tables in your Database-2. Now what you need is to just populate the data from Database-1This might result in error, if any of the tables have referential integrity on them.
From 10g documentation :
Restrictions on Truncating Tables
You cannot individually truncate a table that is part of a cluster. You must either truncate the cluster, delete all rows from the table, or drop and re-create the table.
You cannot truncate the parent table of an enabled referential integrity constraint. You must disable the constraint before truncating the table. An exception is that you can truncate the table if the integrity constraint is self-referential.
If a domain index is defined on table, then neither the index nor any index partitions can be marked IN_PROGRESS.I would go for normal MERGE. Also change the cursor to select table names by first modifying the child tables and then the parent table.
Similar Messages
-
APEX Application accessing data from two different databases
Hi All,
Currently as we all know that APEX Application resides in database and is connected to the schema of that database.
I want APEX Application to be running and accessing data from two different databases. Elaborating my question,
Currently, my APEX Production Application is connected with XXXX Schema of DB1 Database(Where APEX Resides). Now I want to add some pages into this APEX Application for REPORT Purpose, But I want to connect this REPORT APEX Pages to get data from Different Schema YYYY for Database DB2.
Is it possible to configure this scenario?
The reason for doing this is to avoid the REPORT related (adhoc queries) resource utilization effect on Production DB1 Database.
Thanks
Nil1. If you do the joining of two or more tables in DB1 then all data is pulled over to DB1 and then the join is executed: so more data over the databaselink and more work for DB1. Better keep the joining stuff where the data resides and just pull exactly that data over that you need.
2. Don't know about your different block sizes. Seems a nice question for one of the other forums (DBA or SQL).
3. I mean create synonyms on DB1 for reports VIEWS in DB2.
Hope all is clear! -
How to use %Type declaration with table residing in a different database
How can I use the %TYPE declaration if the table is from a different database.
E.g
v_business_unit ps_jrnl.header.business_unit%TYPE;
In the above declaration statement,the table 'ps_jrnl_header' resides in a different database(Database A) from the one I am currently in( Database B).(This is because data needs to be extracted from Database A into Database B).1. Create a database link to the other database (this probably already exists since your proc is interacting with that database)
2. Create a synonym for the table in the other database
create synonym foo for ps_jrnl.header@database_a;3. Reference the synonym in your variable declaration:
v_business_unit foo.business_unit%TYPE; -
How to compare table data and table field
Hi buddy,
I have some question about how to compare table data and table field.
1. I know there is one method: CL_ABAP_UNIT_ASSERT=>ASSERT_TABLE_CONTAINS , it use in unit test to compare the table data(A and B) , you can loop table A into structure A1, then use this mehtod it can compare whether table B contain structure A1. but when I try to use this in main program it will dump.
CL_ABAP_UNIT_ASSERT=>ASSERT_TABLE_CONTAINS(
LINE = A1
TABLE = B ).
Is there any method or FM can be used to compare the table data ?
2. I also want to compare two table field , try to find out the different. How to realize this.
Thank you for your sincerely answer.Hi Zongjie,
What`s the difference, if you using loop A into wa_A, read table B into wa_B with all field, then compare with wa_A and wa_B.
The question 2, seems no standard FM available here.
Loop A into wa_A.
Loop B into wa_B.
if wa_A-field1 eq wa_B-field1.
endif.
if wa_A-field2 eq wa_B-field2.
endif.
endloop.
endloop.
regards,
Archer -
I am unable to connect to two different wi if at different locations having same user name but different password one is at home other at work
I was able to do a full reset on the router (pushing the tiny button near the power input). Then ran through the setup process and it started working on my device.
-
How to compare table data available in two different databases
Hi,
I need to compare two tables data in available in two databases - how easly I can do that .. I have Table A in Database A and Table A in Database B which is snapshot of DB A.TableA - but here are some discrepencies now I need to match two tables .. but no extra space available, so no exp imp.
Thanks in advance,
ChitrasenHI,
What is the difference that you are looking for, if it si for some records missing in some tables you could use MINUS and get the output. IF you are looking to compare the TABLE structure then you could look into the datadictionary VIEWS of both the database's and check the difference.
Thanks -
Joining Querry to check data in two different database tables
Hi,
I have table employee in sqlserver and oracle database.I have to perform joining based on emp id.I know how to perform join if tables are present in one
database.But for different database tables any one can explainDBLINK AND Understanding Oracle Heterogeneous Services
1) http://docs.oracle.com/cd/B28359_01/gateways.111/b31042/newoverview.htm
2) http://docs.oracle.com/cd/B28359_01/gateways.111/b31042/configodbc.htm
Ramin Hashimzade -
Compare table data between two schemas?
Hi,
I am looking for a script to compare the table data between the schemas (two different databases)? I know how to compare table by table but looking for a generic script where I can compare all the tables data from one schema to another schema?
Thanks a lot...here the idea, adapt it with your needs :)
Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.7.0
Connected as SYS
SQL> create user user1 identified by user1;
User created
SQL> grant create session to user1;
Grant succeeded
SQL> grant create table to user1;
Grant succeeded
SQL> alter user user1 quota 10m on DATA;
User altered
SQL> create user user2 identified by user2;
User created
SQL> alter user user2 quota 10m on DATA;
User altered
SQL> grant create table to user2;
Grant succeeded
SQL> grant create session to user2;
Grant succeeded
SQL> create table user1.test(a Number) tablespace DATA;
Table created
SQL> create table user2.test(a Number) tablespace DATA;
Table created
SQL> insert into user1.test values (1);
1 row inserted
SQL> insert into user1.test values (2);
1 row inserted
SQL> commit;
Commit complete
SQL> insert into user2.test values (2);
1 row inserted
SQL> commit;
Commit complete
SQL> create table sys.logs(Diff number) tablespace data;
Table created
SQL> select * from sys.logs;
DIFF
SQL>
CREATE OR REPLACE PROCEDURE TEST_MY_DIFF IS
CURSOR CUR_ IS
SELECT D.TABLE_NAME T_NAME FROM DBA_TABLES D WHERE D.OWNER = 'USER1';
W_DIFF NUMBER;
TYPE CV_TYP IS REF CURSOR;
CV CV_TYP;
BEGIN
EXECUTE IMMEDIATE 'TRUNCATE TABLE SYS.LOGS';
FOR I IN CUR_ LOOP
W_DIFF := 0;
OPEN CV FOR 'select count(*)
from
( select * from USER1.' || I.T_NAME || '
minus
select * from USER2.' || I.T_NAME || ' )
union all
( select * from USER2.' || I.T_NAME || '
minus
select * from USER1.' || I.T_NAME || ')
LOOP
FETCH CV
INTO W_DIFF;
INSERT INTO SYS.LOGS VALUES (W_DIFF);
COMMIT;
EXIT WHEN CV%NOTFOUND;
END LOOP;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
SQL> BEGIN
2 test_my_diff;
3 end;
4 /
PL/SQL procedure successfully completed
SQL> select * from sys.logs;
DIFF
1
1 -
JDBC Lookup - Import table data from a different schema in same DB
Hi XI Experts,
We are facing an issue while importing a Database table into the external definition in PI 7.1.
The details are as below:
I have configured user 'A' in PI communication channel to access the database. But the table that I want to access is present in schema "B". Due to this, I am unable to view the table that I have to import in the list available.
In other words, I am trying to access a table present in a different schema in the same database. Please note that my user has been given all the required permissions to access different schema. Even then, I am unable to access the table in different schema.
Kindly provide your valuable suggestions as to how I can import table which is present in another schema but in the same Database.
Regards,
SubbuIf you are using PI 7.1, then you can do JDBC Lookup to import JDBC meta data (table structures from DB). Configure a jdbc receiver communication channel where you specify username and password which has permission to access schema A and Schema B of database. Specify database name in the connection string. Then you might have access to import both schema.
Please refer these links
SAP PI 7.1 Mapping Enhancements Series: Graphical Support for JDBC and RFC Lookups
How to use JDBC Lookup in PI 7.1 ? -
Different date format in different database..
Hi,
We have two database (10g) with same NLS settings.When we are reading the data from a table and assigning the value to XML tags using oracle.xml.sql.query.OracleXMLQuery class , with one database connection, the data format is coming as MM/DD/YYYY like <PYMT_DATE>7/23/2008 0:0:0</PYMT_DATE>
but with other database it is coming as YYYY-MM-DD like <PYMT_DATE>2009-08-10</PYMT_DATE>..
Can somebody help me out ?hi..
Check the data format used to retrieve the date in the query ..
TO_DATE (......................)
Check whether both the db's are having same conversions.. -
In case of Active Data Guard can i run different database versions (11.2.0.3 and 11.2.0.4) at Primary and DR for production environment ? And will having RAC in environment make any difference?
Hi,
>>In case of Active Data Guard can i run different database versions (11.2.0.3 and 11.2.0.4) at Primary and DR for production environment ?
As per normal Data Guard requirement, Oracle 11.2 does support flexibility where Primary and Standby may have different hard wares such as CPU architecture and OS etc. but the Oracle RDBMS software version must be the same. Having said so does not mean it will not support it. Beginning with 11.1.07, a physical standby database can be used to execute a rolling database upgrade to a new Oracle Patch Set or database release by using the transient logical rolling database upgrade process. It means you can have with different database version but for how long, you need to check above documents.. For complete information you should read this note:
Data Guard Support for Heterogeneous Primary and Physical Standbys in Same Data Guard Configuration (Doc ID 413484.1) &
http://www.oracle.com/technetwork/database/features/availability/maa-wp-11g-transientlogicalrollingu-1-131927.pdf
2) >> And will having RAC in environment make any difference?
NO. You can find answer at - https://docs.oracle.com/cd/E11882_01/server.112/e41134/standby.htm#SBYDB4716
**The primary database can be a single instance database or an Oracle Real Application Clusters (Oracle RAC) database. The standby databases can be single instance databases or Oracle RAC databases.
HTH,
Pradeep -
Table Data Join across different hosts.
I'm trying to create a table using data from three different tables on two different databases, two on one host, the third being on a different one. Is is possible?
Example:
Database: DB1
Table: Table1 t1
Host: Host1
User: dbuser1
Pass: dbpass1
Database: DB2
Table: Table2 t2
Host: Host2
User: dbuser2
Pass: dbpass2
Database: DB2
Table: Table2a t2a
Host: Host2
User: dbuser2
Pass: dbpass2
If all 3 tables were on the same host, I would write the query as:
select t1.column1,t2.column2,t2a.column3
from table1 t1,table2 t2,table2a t2a
where t1.column1=t2.column1
and t1.column2=t2.column2
and t1.column1=t2a.column1
and t2a.column2=t2.column2
I know it's going to a lot more difficult than the above. If someone could please help me, I'd greatly appreciate it.
Thank you,
DanielJust to make sure that you know that is almost as easy as you thought. It sounds like this is a one time thing, but please follow the recommendations of others as well:
Make sure you can connect to both DB1 and DB2 from host1.
From DB1
create database link DB2 connect to dbuser2 identified by dbpass2 using 'DB2';
select t1.column1,t2.column2,t2a.column3
from table1 t1,table2@DB2 t2,table2a@DB2 t2a
where t1.column1=t2.column1
and t1.column2=t2.column2
and t1.column1=t2a.column1
and t2a.column2=t2.column2;
Go and take a nap.
And the performance saving synonyms wink wink....
create synonym db2table2 for table2@DB2;
create synonym db2table2a for table2a@DB2;
Presents us with this query:
select t1.column1,t2.column2,t2a.column3
from table1 t1,db2table2 t2,tdb2table2a t2a
where t1.column1=t2.column1
and t1.column2=t2.column2
and t1.column1=t2a.column1
and t2a.column2=t2.column2;
As you can see all it really does is give you a layer abstraction, nothing performance wise.
-J -
Compare table data with data in csv file
Hi, I have a database table with ~32 milj rows. I want to compare the data from a csv file(~ 1500000 rows) with the data in a specific database column. And as a result I want to see what rows exists in both the csv file and db and what records in csv file are unique. The text I'm searching for is VARCHAR2. I am not allowed to export the database table so that's not an alternative. This is also a production environment so one need to be careful not disturbing the production.
Rgds J2c0eaa24-46c9-4ff7-9f01-564f37567899 wrote:
Hi, I have a database table with ~32 milj rows. I want to compare the data from a csv file(~ 1500000 rows) with the data in a specific database column. And as a result I want to see what rows exists in both the csv file and db and what records in csv file are unique. The text I'm searching for is VARCHAR2. I am not allowed to export the database table so that's not an alternative. This is also a production environment so one need to be careful not disturbing the production.
Rgds J
How do I ask a question on the forums?
https://forums.oracle.com/message/9362002#9362002
Does CVS fille reside on DB Server system now? -
Restore RMAN Backup in Different Database on Same RAC
We have 11gR2 2 node RAC on Linux. ASM and OMF is used for database. The database on it is backedup using RMAN.
We want to test the RMAN backup by restoring it to a new database on same server.
Can someone guide me to steps on how this can be achieved. I'm afraid this should not affect the actual database.
Thanks a lot.Hi,
Yes, this can be done without disturbing your source db. Need more information on your DB structure (datafile asm diskgroups), all you need to do is restore as single node and convert to rac, since you want to test rman restore, you can restore to single node to prove your RMAN backups are intact.
Changes in init.ora
==============
db_file_name_convert= ("source dir structure","target dir structure")
log_file_name_convert=("source dir structure","target dir structure")
cluster_database=false
event="10298 trace name context forever, level 32"
_no_recovery_through_resetlogs=TRUE
Set new database sid (export ORACLE_SID=NEW_SID)
sql>startup nomount;
rman auxiliary /
rman>duplicate database to "NEW_SID" backup location "Your RMAN Backup location";
The above are very high level general steps, please do take other steps into consideration as per your environment. -
Combine 2 Business services having same schema
All,
This is a straight forward case, I am sure this is easy, but since Im a beginner I cant get quick answer.
I am trying to achieve something like A+B=C, where A and B are 2 business services having exact schema, and C is my new Business service that is a combination of A and B.
How do I achieve this in ALSB? please suggest
Thanksdoes it mean that C is going to have two portTypes (portType of A and portType of B)?
If that is the case then you can create your business service in ALSB and a proxy service. The proxy service will simply pass the inbound message to your business service.
Hope it helps.
Maybe you are looking for
-
How to use a Crystal Reports Query as datasourc in an other Cristal Report
Hi I would like to read a File in a CR Report, change some data and use the output as datasource in an other Criystal Reports Report. Is ist possible to use a Crystal Reports Report as datasource for an other Crystal Reports Report? Thomas Edited by
-
I have a debit master card and it says payment method decelined so I contacted my bank and thay said that apple had a lot of fraudulent charges being made was wondering if someone could help me
-
Photoshop and Lightroom 5 from the Cloud problem.
Just purchased and downloaded Photoshop and Lightroom 5 from the Cloud. Had a problem with Lightroom when trying to mate it up with LR4 can I delete LR5 and use the Cloud installer to reinstall?
-
When does iTunes Match charge you
im thinking of getting itunes match and when does it charge you for money, and do i need to use a credit card for itunes match or can i use an itunes card. one more thing, when i add unrealesed music to my itunes library will it be added to itunes ma
-
how to reset keychain i forgot my username and password.i forgot my username and password in moblie me how to reset.