Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Comparing data between two tables in two schema

Re: Comparing data between two tables in two schema

From: Jan Pruner <jan_at_pruner.cz>
Date: Tue, 02 Oct 2001 06:13:30 -0700
Message-ID: <F001.0039E8B5.20011002051520@fatcity.com>

This function comapres two tables.
It's easy to write a cycle for tables in two schemas. Enjoy it.

Jan Pruner

create function compare_tables( tbl1 VARCHAR2, tbl2 VARCHAR2) return NUMBER /* Function compares content of two identical tables || tbl1, tbl2 are names of tables in format owner.table_name || 2001, Jan Pruner
*/
AS

        cnt1    number;
        cnt2    number;
        cnt3    number;
        res     number;
        sql_stmt        varchar2(100);

begin
-- count of tuples in 1. table
sql_stmt := 'select count(*) into cnt1 from :1'; EXECUTE IMMEDIATE sql_stmt USING tbl1;
-- count of tuples in 2. table
sql_stmt := 'select count(*) into cnt2 from :1'; EXECUTE IMMEDIATE sql_stmt USING tbl2;
-- count of tuples in union of tables
sql_stmt := 'select count(*) into cnt3 from ( select * from :1 UNION select * from :2) t';
EXECUTE IMMEDIATE sql_stmt USING tbl1, tbl2;

if (cnt1 = cnt2) and (cnt2 = cnt3) then

        res := 0 ;
else

        res := 1 ;
end if;
return res;
end;

> From: "Rao, Maheswara" <Maheswara.Rao_at_Sungardp3.com>
>
> >Reply-To: ORACLE-L_at_fatcity.com
> >To: Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com>
> >Subject: Comparing data between two tables in two schema
> >Date: Mon, 01 Oct 2001 12:29:41 -0800
> >
> >List,
> >
> >I have two schema. The tables in both schema are having same name and
> >structures.
> >
> >Is there any tool to compare the data between two schema tabels?
> >
> >Thanks,
> >
> >Rao

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Jan Pruner
  INET: jan_at_pruner.cz

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Tue Oct 02 2001 - 08:13:30 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US