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" <[EMAIL PROTECTED]>
>
> >Reply-To: [EMAIL PROTECTED]
> >To: Multiple recipients of list ORACLE-L <[EMAIL PROTECTED]>
> >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: [EMAIL PROTECTED]

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: [EMAIL PROTECTED] (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).

Reply via email to