Two tables columns compare

Hi
Using below sql get the columns discrepncy .I want to display the discprency of columns from two tables in form of flat file using pl/sql.
select col1,col2 from A
minus
select * from B -- Rows in A that are not in B
union all
select col1,col2 from B
minus
select col1,col2 from A ----- rows in B that are not in A
Thanksin advance
MR

Hi
Wrote the cursor for this ,I am not getting expected o/p .Please any help
DECLARE
CURSOR C1 IS SELECT ACCOUNT_CUST_CD , account_contact_person_cd
FROM account where ACCOUNT_CUST_CD='1-411FQ'
AND account_contact_person_cd IS NOT NULL ORDER BY account_contact_person_cd ;
CURSOR C2 IS SELECT ACCOUNT_CUST_CD , account_contact_person_cd FROM bill_bkp
where ACCOUNT_CUST_CD='1-411FQ'AND ACCOUNT_STATUS_DESC='Blacklisted Customer'ORDER BY account_contact_person_cd ;
BEGIN
FOR REC1 IN C1
LOOP
FOR REC2 IN C2
LOOP
IF REC1.account_contact_person_cd <> REC2.account_contact_person_cd or
REC1.ACCOUNT_CUST_CD<>REC2.ACCOUNT_CUST_CD
THEN
DBMS_OUTPUT.PUT_LINE(REC1.account_contact_person_cd||REC2.account_contact_person_cd||REC1.ACCOUNT_CUST_CD||REC2.ACCOUNT_CUST_CD);
END IF;
END LOOP;
END LOOP;
END;
Thanks and Regards,
MR

Similar Messages

  • Compare two table columns

    hi all,
    i am using db10g.
    my task is to compare two table's data for example
    table1 is having
    col1 col2 col3
    a b c
    e f g
    table2 is
    col4 col5 col6
    a e c
    e f g
    so i have to compare col1 first record and col4 first record.
    in otherwords first table first column first item with second table first table first value and so on.
    for ex: a= a
    b= e
    c= c etc
    how can i acheive this?
    both are database tables.
    i cannot use minus function because data types are different for the corresponding column
    how can i compare it?
    Thanks..
    Edited by: user13329002 on Jan 13, 2011 1:09 AM

    Hi,
    Try this
    select
        case
            when a.col1 = b.col1 then 'EQUAL' else 'NOT EQUAL' end column1,
        case
            when a.col2 = b.col2 then 'EQUAL' else 'NOT EQUAL' end column2,
        case
            when a.col3 = b.col3 then 'EQUAL' else 'NOT EQUAL' end column3 
    from (select col1,col2,col3,rownum rn from table1) a,
                                (select col1,col2,col3,rownum rn from table2) b where a.rn = b.rn Try to see how you order the rows of the two tables.
    cheers
    VT

  • Sql table function that compares two tables column structure and returns each difference as a record in the returned table

    hi,
    Does anyone have or can show me the principle of a such kind of function ?

    see
    http://geekswithblogs.net/leonardm/archive/2010/01/14/table-schema-comparison-in-sql-server.aspx
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Multiplying two table columns

    Hello,
    What I want to do is very simple: I have a read-only table, displaying a product price and its quantity. I want a third column in which I could display the total price.
    I tried #{row.SalesPrice*row.Quantity} but I had this exception:
    Attempt to coerce a value of type "oracle.jbo.domain.Number" to type "java.lang.Long"
    So I tried : #{row.SalesPrice.multiply(row.Quantity)}
    But now I have javax.faces.el.ReferenceSyntaxException: row.SalesPrice.multiply(row.Quantity)
    Do you know what is the correct expression?
    Thanks,
    Romain

    you can use a convertNumber
    I guess your using an output text? put the following code inside it:
    <f:convertNumber groupingUsed="false"/>
    <af:outputText value="#{bindings.<yourattr>}">
      <f:convertNumber groupingUsed="false"/>
    </af:outputText>

  • Join two tables - column merge

    Table1 - Product ID, Description
    Table 2 - Product ID, Cost
    I want the result to contain Product ID, Description and Cost. Which process should I use?
    Balaji

    Define a lookup against the table you want to check against. (Right-click on Reference Data node in the project browser, Add Lookup). The lookup can be to either staged data or external data (if the data is dynamic)
    Then add a Lookup and Return processor to your process and configure the options. You can check for the correct cardinality if required.
    If you are doing a 1:M lookup and want to create a 'join' in the process, input all the array attributes from Lookup and Return into a single Split Records from Array processor and then either Write or do other downstream processing on the joined stream.

  • Combine Two table columns

    SELECT providerid, SUM(COUNT) FROM appdev.usercounts
    WHERE counttime BETWEEN SYSDATE - 30/1440 AND SYSDATE- 15/1440 GROUP BY providerid ORDER BY providerid
    W     697
    U     813
    T     143
    S     2
    SELECT providerid, SUM(COUNT) FROM appdev.usercounts
    WHERE counttime BETWEEN (SYSDATE -1) - 30/1440 AND (SYSDATE-1)- 15/1440 GROUP BY providerid ORDER BY providerid;
    W     450
    U     571
    T     80
    S     2
    I wnat output as like
    W     697 450
    U     813 571
    T     143 80
    S     2 2
    please help
    Thanks
    Praveen

    "COUNT", is that the real column name? It could become very confusing.
    Not tested for obvious reasons, but this should be close :
    SELECT providerid
         , sum(
             case when counttime between sysdate - 30/1440 and sysdate - 15/1440 then count end
           ) as cnt1
         , sum(
             case when counttime between (sysdate-1) - 30/1440 and (sysdate-1) - 15/1440 then count end
           ) as cnt2
    FROM appdev.usercounts
    WHERE ( counttime between sysdate - 30/1440 and sysdate - 15/1440 )
       OR ( counttime between (sysdate-1) - 30/1440 and (sysdate-1) - 15/1440 )
    GROUP BY providerid
    ORDER BY providerid
    ;

  • Using An Update with a Literal Value Based on Equality Between Two Tables

    I need to update table1 code_val with a literal value: 'Y' where table1 column grpid matches table2 column grpid.
    I have found all sort of info on the web about updating a value from, for example, a table2 field into table1, but I can't find anything where i assign the value where two table columns match.
    It would be something like this:
    update table1
    set code_val = 'Y'
    Where table1.grpid = table2.grpid
    Thanks for any assistance!

    user12296489 wrote:
    I need to update table1 code_val with a literal value: 'Y' where table1 column grpid matches table2 column grpid.
    I have found all sort of info on the web about updating a value from, for example, a table2 field into table1, but I can't find anything where i assign the value where two table columns match.
    It would be something like this:
    update table1
    set code_val = 'Y'
    Where table1.grpid = table2.grpid
    update table1
    set code_val = 'Y'
    Where table1.grpid in (SELECT grpid from table2);

  • How can I make my query to compare only columns of two tables... not the storage information?

    11GR2
    =-----------------------------------
    I am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and  if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
    begin
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY', TRUE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'REF_CONSTRAINTS',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS_AS_ALTER',FALSE);
    End;
    select REGEXP_REPLACE(dbms_metadata_diff.compare_alter('TABLE','TABLE_NAME_A','TABLE_NAME_A','USER1','USER2'),('USER1...'),'', 1, 0, 'i') from dual

    I am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and  if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
    If you want help you have to SHOW us what you are doing and how you are doing it; you can't just try to tell us in your own words.
    We can't see your computer screen.

  • Query for comparing two columns in two tables

    Hai, all,
    I have following two tables and columns, I need to get the rows (all columns) from scott.cp_ip which are not ( the same value present in t1 and also in t2).
    Table scott.cp_ip column cp_ip.vrno = Table scott.cb1 column cb1.cb_vnno
    I used the following query and did not get the correct result:
    select * from scott.cp_ip where cp_ip.vrno in (select cb1.cb_vnno from scott.cb1);
    Can you please tell how it can be solved?
    Thanks in advance.
    Rcs
    SQL> desc scott.cb1;
    Name Null? Type
    ID NUMBER
    SUPCODE NUMBER
    SUPLNAME VARCHAR2(100)
    NAME VARCHAR2(100)
    ITEMCODE VARCHAR2(10)
    RECDOC NUMBER
    RECDATE VARCHAR2(10)
    TOTVALUE NUMBER
    QTY NUMBER
    CB_IPNO NUMBER
    CB_VNNO NUMBER
    CB_VDT VARCHAR2(10)
    CB_AMT NUMBER
    SQL> desc scott.cp_ip;
    Name Null? Type
    ID NUMBER
    VRNO NUMBER
    CODE VARCHAR2(50)
    HEAD VARCHAR2(255)
    PARTI VARCHAR2(255)
    CR NUMBER
    SQL> select * from scott.cp_ip
    2 intersect
    3 select * from scott.cb1;
    select * from scott.cp_ip
    ERROR at line 1:
    ORA-01789: query block has incorrect number of result columns
    SQL> (select * from scott.cp_ip
    2 minus
    3 select * from scott.cb1)
    4 union all
    5 (select * from scott.cb1
    6 minus
    7 select * from scott.cp_ip);
    (select * from scott.cb1
    ERROR at line 5:
    ORA-01789: query block has incorrect number of result columns
    SQL> select * from scott.cp_ip where cp_ip.vrno in (select cb1.cb_vnno from scott.cb1);
    result=instead of 1408 rows, 1481 rows (excess 73 rows) getting!
    ----------

    Instead of SELECT * write only the column that you want to compare. I guess that would be cb1.cb_vnno and cp_ip.vrno.

  • How to compare the names and types columns of two tables?

    Assume I have two tables aaa and bbb
    How do I compare the columnnames and types of the two columns?
    It should not matter if one of them has e.g. an additional index.
    Furthermore it does not matter if the rows/row values differ.
    Peter

    SQL> desc emp
    Nome                   Nullo?   Tipo
    EMPNO                  NOT NULL NUMBER(4)
    ENAME                           VARCHAR2(10)
    JOB                             VARCHAR2(9)
    MGR                             NUMBER(4)
    HIREDATE                        DATE
    SAL                             NUMBER(7,2)
    COMM                            NUMBER(7,2)
    DEPTNO                          NUMBER(2)
    SQL> desc emp2
    Nome                   Nullo?   Tipo
    EMPNO                  NOT NULL NUMBER(4)
    ENAME                           VARCHAR2(10)
    MGR                             VARCHAR2(10)
    HIREDATE                        DATE
    SAL                             NUMBER(7,2)
    COMM                            NUMBER(7,2)
    DEPTNO                          NUMBER(2)
    NEWCOL                          NUMBER
    SQL> with t1 as
      2  (select column_name, data_type from user_tab_columns where table_name='EMP'),
      3  t2 as
      4  (select column_name, data_type from user_tab_columns where table_name='EMP2')
      5  Select a.column_name, a.data_type, b.column_name, b.data_type
      6  from t1 a full outer join t2 b on a.column_name=b.column_name;
    COLUMN_NAME                    DATA_TYPE                      COLUMN_NAME                    DATA_TYPE
    EMPNO                          NUMBER                         EMPNO                          NUMBER
    ENAME                          VARCHAR2                       ENAME                          VARCHAR2
                                                                  NEWCOL                         NUMBER
    MGR                            NUMBER                         MGR                            VARCHAR2
    HIREDATE                       DATE                           HIREDATE                       DATE
    SAL                            NUMBER                         SAL                            NUMBER
    COMM                           NUMBER                         COMM                           NUMBER
    DEPTNO                         NUMBER                         DEPTNO                         NUMBER
    JOB                            VARCHAR2
    Selezionate 9 righe.Max
    http://oracleitalia.wordpress.com
    Edited by: Massimo Ruocchio on Feb 21, 2010 1:27 AM
    Changed query.

  • Comparing two columns in two tables using partial text strings and copying data between tables

    I have two tables:
    The Vendor table is supplied by a clothing manufacturer and lists product data by row with a column that contains a unique manufacturer ID, such as T5C4.  In this table is a short product description and a long product description that I need to find and copy into the second table, Inventory.
    The Inventory table is an export from our Magento store.  Each row contains a unique inventory number in a column that includes but does not match the unique manufacturer ID from the Vendor table.  For example, the unique inventory number could be T5C4-W12, or RED-T5C4W12 or some other variation.
    For each product in Inventory, I need to find the matching product in Vendor, and then copy the short description and long description from Vendor to Inventory.
    Any tips?  Thanks!
    Karl

    Karl,
    Here's a start, as you requested.
    The formula for Our Inventory Row is:
    =IFERROR(MATCH("*"&A&"*", Our Inventory :: A, 0), "n/a")
    The formula for Brief Description in the inventory table is:
    =IFERROR(INDEX(ABC Products :: $A$1:$C$9,MATCH(ROW(), ABC Products :: $D, 0), 2), "n/a")
    The formula for the Full description in the inventory table is:
    =IFERROR(INDEX(ABC Products :: $A$1:$C$9,MATCH(ROW(), ABC Products :: $D, 0), 3), "n/a")
    The Manufacturer's table knows the concise product numbers, so it has the ability to search the Inventory table for it's product id's using wildcards and it then displays the line number of the item in the inventory table. The Inventory table can then search the manufacturer's table for its row number and can reference the brief and full descriptions.
    This approach has a serious limitation. It will only find the first occurrence in the inventory. Now, if you want to accept this, you can sort all the found descriptions and pull them out of the inventory table, and then the next product in line will display it's description too.
    I wish I could do better with this, but it's all I can come up with at this point, knowing only what you have told me.
    Jerry

  • Compare two tables having different number of rows based on 2 columns

    Hi,
    I am having two tables table a having field1, field2 and table b having fields field1 and field2.
    I want those records from table a in which field1 of table a is not matching to field1 of table b and field2 of table b not matching to field2 of table b, but i also want the bifurcation of records as whether field 1 is not matching, field 2 is not matching or both fields 1 & 2 are not matching.
    e.g.
    table a table b
    field1 field2 field1 field2
    1 6 12 5
    2 5 1 9
    13 51 13 51
    45 31 99 121
    33 45
    In this case my output should be
    table a
    field1 field2 Mtchng_Field
    1 6 Field 2 not mtchng
    2 5 Field 1 not mtchng
    45 31 Feild1 and Field2 both not matching
    How would i get my result in the required format.

    sql>select * from t1;
    N1 N2 
    1   6 
    2   5 
    13  51 
    45  31 
    33  45 
    sql>select * from t2;
    N1 N2 
    12  5 
    1   9 
    13  51 
    99  121
    sql>
    select n1,n2,decode(nvl(p1,0)+nvl(p2,0),0,'No match',1,'F2 not match',2,'F1 not match','Match') status
    from(
      select n1,n2,(select 1
                   from t2 where n1=t1.n1) p1,(select 2
                                           from t2 where n2=t1.n2) p2
    from t1);
    N1 N2 STATUS 
    1   6   F2 not match 
    2   5   F1 not match 
    13  51  Match 
    45  31  No match 
    33  45  No match
    Message was edited by:
            jeneesh
    Message was edited by:
            jeneesh
    Some problems...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Compare two columns in two tables

    Hi All,
    I have two tables have no relations, but one have first_name, last_name and address in text fields,
    table B has name , address but i need to search in the field to find the match.
    EX: Table A
    first_name: LLoyd
    last_name: Fernanda
    address: 123 cololbl av
    Table B
    name: peter lloyed Fernanda
    address: 123 cololbl av E florida
    this is like i have name and address, you get in a another table names and address not formatted well, i need to find the matches at lest 80 to 90%
    Thx
    Harsha

    Unfortunately you did not mention your db version.
    I think from 10g on you can use UTL_MATCH as e.g. in:
    SQL>  with a as (
    select 'LLoyd' first_name, 'Fernanda' last_name, '123 cololbl av' address from dual
    , b as (
    select 'peter lloyed Fernanda' name, '123 cololbl av E florida' address from dual
    select *
      from a, b
    where utl_match.jaro_winkler_similarity (
                    first_name || last_name,
                    name
               ) > 50
         and utl_match.jaro_winkler_similarity (
                    a.address,
                    b.address
               ) > 90
    FIRST_NAME LAST_NAME ADDRESS        NAME                  ADDRESS_1              
    LLoyd      Fernanda  123 cololbl av peter lloyed Fernanda 123 cololbl av E florida
    1 row selected.

  • Is there an easy way to compare two null columns?

    I need to compare a significant number of columns between records in two tables for a data conversion. I really need a comparison that will return true if: 1) both columns are null; or 2) both columns are not null and equal. I want it to return false if: 3) one column is null and the other is not; or 4) both columns are not null and are not equal. I am trying to find records which are not exact matches.
    I found documentation at oracle-base.com about the SYS_OP_MAP_NONNULL function that would do what I want, but I don't want to use this since it's an undocumented feature and my code will be in production for a period of time.
    I would rather not have to use a construct like this for each and every column I'm comparing:
              a.col is null
              and b.col is null
         or (
              a.col = b.col
    )Also, I know about the NVL function, but I'm comparing columns which are entered by users, and I'm not comfortable substituting any values for null because those values might actually exist in the data.

    Performance wasn't the issue but they will be about the same anyway. The issue was avoiding the messy syntax needed to do the job.
    Which of these looks easier to you if you had to understand and maintain the code or add new columns
    >
    I would rather not have to use a construct like this for each and every column I'm comparing:
              a.col is null
              and b.col is null
         or (
              a.col = b.col
    >
    or
    1 = DECODE (a.col, b.col, 1)So if, like the OP, you had to 'compare a significant number of columns' which syntax would you use?

  • 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

Maybe you are looking for

  • Disable scrolling animations in Mail

    Hi everybody, I really like the new Mail-App in Lion. But is there a possibility to disablle the scrolling-animation (wenn you press FN+Down/Up-Arrow-Key) in Mail that it behaves like Snow Leopard Mail. If you want to flip through multi-pages-mails v

  • My webcam is no longer on my MacBook?

    I signed up for Skype but nobody can see me because my WebCam somehow no longer exists. When I go into preferences it says "There is no camera connected to this computer". I know there's a camera I can see it right in front of me. So how do I get it

  • Safari hangs and won't force quit

    I tried searching for this but the problem prevented that. After repairing my permissions yesterday, Safari won't let me do certain things like right-clicking an image or goto various sites or let my use tabbed browsing. I just get stuck with the spi

  • My iPhone 4S has crashed 7 times. I hold down the home key and on button to reboot. I tried a restore but has crashed once since. Do I have a faulty phone ?

    My new iPhone 4S has crashed 7 times ie the screen does not come back on when I press the home key. I hold down the home key and on button to reboot and it always comes back. I tried a restore but it has crashed once since. Is this right  ? Do I have

  • ABAP Certfication Q's

    Hi Experts, Can U please provide me with the answers for the following Q's. 4. An event starts with an event keyword and ends with: A: Program execution. B: END-OF-EVENT. C: Another event keyword. D: END-EVENT. 6. The following code indicates: SELECT