Script to compare 2 tables and retrieve the differences in records data

Dear All,
please I need a script to compare two oracle database tables and retrieves the differences in data records between the two tables.
I have tried this one :
-- all rows that are in T1 but not in T2
(select * from T1 minus select * from T2)
union all
-- all rows that are in T2 but not in T1
(select * from T2 minus select * from T1);
But it generates the following error:
ORA-01789: query block has incorrect number of result columns
Thank you for your cooperation , please it is urgent

ok I used this statement with dblink, the problem is that i cannot use PL/SQL developer since it is a process repeated for 300 tables , that why i am trying to automate it:
-- all rows that are in T1 but not in T2
(select * from schema.T1minus select * from T2@dblink_name)
union all
-- all rows that are in T2 but not in T1
(select * from T2@dblink_name minus select * from schema.T1);
I created the db link on a database A and when i run the statement
(select * from schema.T1minus select * from T2@dblink_name)
on the database B i get the error ORA-02019: CONNECTION DESCRIPTION FOR REMOTE DATABASE NOT FOUND.
DOes anybody have an idea please

Similar Messages

  • Compare two tables and log the difference

    Hi,
    I want to compare two tables and log the difference in new table with the fields as (old value,new value, column name). The column name should be the changes value column

    Can you show an example?
    SELECT Foo.*, Bar.*
       FROM Foo
            FULL OUTER JOIN
            Bar
            ON Foo.c1 = Bar.c1
               AND Foo.c2 = Bar.c2
               AND Foo.cn = Bar.cn
     WHERE Foo.key IS NULL 
        OR Bar.key IS NULL; 
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Compare csv and output the difference

    Hi
    I have two csv files
    Oldcsv
    Server
    IP
    State
    Box1
    192.168.25.1
    Enabled
    Box2
    192.168.25.2
    Enabled
    Box3
    192.168.25.3
    Enabled
    newcsv
    Server
    IP
    State
    Box1
    192.168.25.1
    Enabled
    Box2
    192.168.25.2
    Disabled
    Box3
    192.168.25.3
    Disabled
    OUtput should be
    Server
    IP
    OldState
    NewState
    Box2
    192.168.25.2
    Enabled
    Disabled
    Box3
    192.168.25.3
    Enabled
    Disabled
    Actuall files contains thousand of boxes.
    I have tried compare-object 
    with passthru . But unable to get the desired result. Please Assit/Guide Me.
    Thanks
    Neo

    ## checking differences
    $a = Import-Csv .\csv1.csv
    $b = Import-csv .\csv2.csv
    $compare = Compare-Object -ReferenceObject $b -DifferenceObject $a -Property State -PassThru
    Write-host "Change of state"
    $result = $compare |?{$_.Sideindicator -eq "<="}
    $result |%{$c=$_.server;$compare |?{$_.server-eq $c}}
    I cant figure out how to put OldState and NewState together.. lol
    Trying this way but still no luck
    $compare|?{$_.Sideindicator
    -eq"<="}
    |select@{n="Server";e={$_.server}},@{n="OldState";e=
    .... get the State from variable $a where server equal $_ .. 

  • Delete records in a table and at the same time print out for reference

    I am working on a req to delete some records from a table and at the same time, record/print the deleted records in the outstream (DBMS_OUTPUT.PUT_LINE)
    DECLARE
    v_rec_po hst_po%ROWTYPE;
    BEGIN
    DELETE FROM hst_po po
    WHERE abbrpoid = '&opportunity_code'
    AND updatedby = (SELECT employeeid
    FROM tes_employee
    WHERE name = &emp_name)
    AND audittimestamp BETWEEN TO_DATE ('&start_timestamp',
    'DD-MON-YYYY HH24:MI'
    AND TO_DATE ('&end_timestamp',
    'DD-MON-YYYY HH24:MI'
    END;
    I was thinking of using returning into and then using DBMS_output to pull out the delted records, but there will be multiple rows deleted fro this statements. I am stuck here..Can anyone help

    How about:
    SQL> create table t
      2  (x int)
      3  /
    Table created.
    SQL> insert into t
      2  select rownum
      3    from all_objects
      4   where rownum <= 10
      5  /
    10 rows created.
    SQL> declare
      2     cnt pls_integer;
      3  begin
      4     delete from t;
      5     cnt := sql%rowcount;
      6     dbms_output.put_line ('Removed: '||to_Char (cnt));
      7  end;
      8  /
    Removed: 10
    PL/SQL procedure successfully completed.Edited by: Alex Nuijten on Jun 4, 2009 8:58 AM

  • How to apply data into 2 tables AND to more than one record in same table?

    Hello,
    I am trying to apply/insert data into 2 tables AND at the same time apply data to more than one record (in the same table). How would I do this in APEX?
    I have updated using one table with no problem, however, when I try updating with the two tables/ multiple record sets, I get errors.
    I appreciate the help.
    Thanks.
    Linda

    You can achieve what you want using PL/SQL. Can you post ur code?

  • Getting the difference between 2 dates

    Hi,
    I am creating a Date object (using today;s day, month and year. hours and minutes come from a config file) and getting the difference between this date and the current date and time.
    My code is as follows:
    I am passing 07:30 into the method as the parameter aSstart_time.
    Calendar newCalendar = Calendar.getInstance(Locale.UK);
        SimpleDateFormat dtformat = new SimpleDateFormat("dd-MM-yy HH:mm");
        int lIYear = newCalendar.get(newCalendar.YEAR);
        int lIMonth = newCalendar.get(newCalendar.MONTH);
        int lIDay = newCalendar.get(newCalendar.DAY_OF_MONTH);
        String lSstartHrs = aSstart_time.substring(0,aSstart_time.indexOf(":"));
        //System.out.println(">>>>>>>>> THE HOURS IS: " + lSstartHrs);
        String lSstartMins = aSstart_time.substring(aSstart_time.indexOf(":")+1,aSstart_time.length());
        //System.out.println(">>>>>>>>> THE MINS IS: " + lSstartMins);
        java.util.Date ldStartTime = new java.util.Date(lIYear,lIMonth,lIDay, Integer.parseInt(lSstartHrs),Integer.parseInt(lSstartMins));
        System.out.println("Year: " + lIYear);
        System.out.println("Month: " + lIMonth);
        System.out.println("Day: " + lIDay);
        System.out.println("Hour: " + Integer.parseInt(lSstartHrs));
        System.out.println("Min: " + Integer.parseInt(lSstartMins));
        System.out.println("The number of milliseconds for current time is: " + newCalendar.getTime().getTime());
        System.out.println("The number of milliseconds for 07:30 is: " + ldStartTime.getTime());
        System.out.println("calendar time: " + dtformat.format(newCalendar.getTime()).toString());
        System.out.println("created time: " + dtformat.format(ldStartTime).toString());
        if(newCalendar.getTime().getTime() < ldStartTime.getTime()){
          System.out.println("The current time is less than the config time (07:30)");
        else{
          System.out.println("The time is greater than 07:30");
        }When I run this program at 10:06am I get the following output:
    Year: 2006
    Month: 1
    Day: 15
    Hour: 7
    Min: 30
    The number of milliseconds for current time is: 1139997962321
    The number of milliseconds for 07:30 is: 61098132600000
    calendar time: 15-02-06 10:06
    created time: 15-02-06 07:30
    The current time is less than the config time (07:30)
    The Date.gettime() method should measure the number of milliseconds after 01-01-1970 so the number of milliseconds for the current time (10:06am) should be greater than the number of milliseconds for 07:30. A you can see in the above output this is not the case.
    Anybody have any idea why this is happening. Am I using the .gettime() method for the correct purpose.
    Any ideas or suggestions would be greatly appreciated.
    Thanks

    It is beacause Calendar use fully defined year as parameter, so Calendar.set(year + 1900, month, date, hrs, min) is (almost) equivalent to new Date(year, month, date, hrs, min)Example:    int year = 85; // old way of specifying a year in a Date
        int month = 3;
        int date = 12;
        int hrs = 12;
        int min = 0;
        Calendar cal = Calendar.getInstance();
        cal.set(year + 1900, month, date, hrs, min);
        Date d = new Date(year, month, date, hrs, min);
        System.out.println(d);
        System.out.println(cal.getTime());You will obtain the same date (except seconds and miliseconds in this case, as they probably won't be zero with Calendar.getInstance(); )

  • How to compare two images and display the difference on Front Panel

    HI..
    I have attached two images.
    I want to compare these two images and subtract the differenc from these two images and display the difference(the mouse) on the front panel
    Anyone can help me?
    Really thanks
    Attachments:
    IMG_2117.JPG ‏1677 KB
    IMG_2118.JPG ‏1650 KB

    The missing thing. You have to keep in mind that what you see is not the same as the camera sees.
    So when using IMAQ Substract it gives you the difference of the value of every single pixel!
    In order to find the mouse as only difference you have to manage that every other pixel value stays the same, e.g. with a proper lightening.
    At the other hand you can combine different filters or alogorithms to get the object, e.g. if the object is darker or brighter then everything else in the image you could use a threshold and then use morphologic operations to get the objects size and position.
    Christian

  • What is the Difference Between Sys Date and Effective Date ??

    Hi Gurus,
    Can any one pls let me know What is the Difference Between Sys Date and Effective Date ??
    with regards
    User600722

    EFFECTIVE DATE usually refers to a date-tracked record (although not exclusively).
    Date-tracked records in Oracle HR have an EFFECTIVE START DATE and an EFFECTIVE END DATE. The record is 'EFFECTIVE' between these dates. In reports, you often use SYSDATE to compare to these two dates to find the CURRENT effective record, e.g. SYSDATE BETWEEN EFFECTIVE START DATE AND EFFECTIVE END DATE.
    When you make changes to a HR record, you can choose between DATE TRACKING options, such as CORRECT or UPDATE (there are others too). CORRECT will overwrite the record and replace the data with your changes. This is normally used when you need to correct something that is wrong. UPDATE will create a new version of the record from the EFFECTIVE START DATE you choose. It will also set the EFFECTIVE END DATE of the previous record to the day before your new record's EFFECTIVE START DATE. That enables a history of records to be maintained so you can see what your data looked like at ay one point in time.
    Regards
    Tim
    Edited by: TimW on Sep 23, 2008 2:37 PM

  • How to disable a single cell in a table (and not the whole column)

    Hi there,
    I've got a webdynpro table with a few columns, rows can be created dynamically through a button in the table toolbar.
    Depending on the value of a certain cell I have to disable another cell (in the same row).
    I tried to manipulate the view in the modifyview but no joy. I also tried to manipulate the attribute property through the coding below:
      DATA lv_knttp TYPE knttp.
      lo_nd_kostl = wd_context->path_get_node( path = `MULTIVALUES.KOSTL` ).
      lo_el_kostl = lo_nd_kostl->get_element( ).
      lo_el_kostl->set_attribute_property(
      attribute_name = 'LTEXT'
              property       = lo_el_kostl->e_property-enabled
              value          = ''
    but it disables the whole column!!!! I just need the cell to be disabled (I thought the code above, through the lead selection, would affect a certain cell only - but I was wrong).
    Any ideas?
    Thanks!!!

    Hi,
    using cell variants you can do this.,
    check this article: [Cell Variants in WDA|http://wiki.sdn.sap.com/wiki/display/WDABAP/WebDynproforABAPCellVariants]
    Instead of binding the read only property of table as a whole , just bind the read only property of column group of table., You can do this bu drill down the table and select the required column and bind the read only column.,
    then In onAction Event of button .,
    loop the table, if condition satisfied set the read only property to true else false.,!!
    hope this helps u.,
    Thanks & regards,
    Kiran

  • What is the difference between delivery date and actual goods issue date?

    Hi ,
    Can you please tell me the difference between Delivery date and Actual goods issue date ?
    Delivery data can be be greater than goods issue date?
    Thanks,
    Ajay

    Hi Ajay,
                  Delivery date means its the original date on which the delivery should be done.Actual goods Issue date is the date on which goods to be delivered according to the purchase order.There can be delay in the delivery so we maintain 2 objects.
    Yes delivery date can be greater than Goods Issue date.
    Hope this clears
    Regards
    Karthik

  • How to get the difference of two dates in years,months and days

    Hi friends,
    how to get the difference of two dates in years,months and days
    for ex 2 years 3 months 13 days
    select (sysdate-date_Start) from per_periods_of_service
    thanks

    Something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
      2             select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
      3             select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
      4             )
      5  -- end of test data
      6  select c_start_date, c_end_date
      7        ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
      8        ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
      9        ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
    10* from t
    SQL> /
    C_START_D C_END_DAT        YRS      MNTHS        DYS
    17-NOV-06 21-JAN-08          1          2          4
    21-NOV-06 17-FEB-08          1          2         27
    21-JUN-06 17-JUL-08          2          0         26
    SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too.

  • If i have an unlocked iphone 5 can i upgrade it to an iphone 5s and pay the difference ?

    if i have an unlocked iphone 5 can i upgrade it to an iphone 5s and pay the difference?

    Then, you own the phone. Your only options are sell the phone yourself or see what programs are offered by third-parties or your carrier.

  • How to Find the highest and lowest cell in a column and figure the difference

    What I am tryng to do is have numbers find the high and low in Cloumn B and and put the difference in B6. So I would need it to Figure out that B3 is the highest and B2 is the lowest and give me the difference of .25 in B6

    Don,
    Begin by making Row 6 a Footer Row. You will find that option in the row tab menu that appears when you hover over the 6 tab and click the triangle.
    Then enter this formula in B6:
    =MAX(B)-MIN(B)
    Regards,
    Jerry

  • Question on Creating table from another table and copying the partition str

    Dear All,
    I want to know whether is there any way where we can create a table using another table and have the partitions of the new table to be exactly like the used table.
    Like
    CREATE TABLE TEST AS SELECT * FROM TEMP;
    The table TEMP is having range and hash partitions.
    Is there any way when we use the above command, we get the table partitions of TEMP to be copied to the new table TEST.
    Appreciate your suggestions on this one.
    Thanks,
    Madhu K.

    may this answer your question...
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:595568200346856483
    Ravi Kumar

  • Nsert/Update and Add Column at the same Table and at the "same" Time

    Hello,
    I want Insert/Update and Add Column at the same Table and at the "same" Time but in different sessions.
    Example:
    At first the "insert/update" statement:
    Insert into TestTable (Testid,Value) values (1,5105);
    After that the "add" statement:
    Alter table TestTable add TestColumn number;
    - sadly now I get the message: ORA-00054: resource busy and acquire with NOWAIT specified
    "insert/update" statement:
    Insert into TestTable (Testid,Value) values (2,1135);
    After that the execute commit.
    I don't know when the first session set the commit statement so I want that the DB the "Alter Table..." statement execute if it's possible.
    If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.
    Thanks for ideas

    Well I want to walk in the rain without and umbrella and still stay dry, but it ain't gonna happen.
    You can't run a DDL statement against a table with transactions pending. Session 2 has to wait until session commits or rollbacks (or until the session is killed). That's just the way it is.
    This makes sense if you think about it. The data dictionary has to be consistent across all sessions. If session 2 was allowed to change the table structure whilst session 1 has a pending transaction then the database is in an inconsistent state. This is easier to see if you consider the reverse situation - the ALTER TABLE statement run by session 2 does a DROP COLUMN TESTID rather than adding a column: now what should happen to session 1's INSERT statement? You have retrospectively invalidated a statement that was perfectly legal when it was executed.
    If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.Fnord.
    Cheers, APC

Maybe you are looking for