Excel/CSV data to Oracle Tables and compare data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vijaya hyd
    New Member
    • May 2013
    • 7

    Excel/CSV data to Oracle Tables and compare data

    I have two excel files(say XL1, XL2) with same structure.
    1) Part of XL1 data may exist in XL2 with few column values changed(modifie d field values)
    2) Few records of XL1 may be delted in XL2(deleted)
    3) New records may be added in XL2(newly added)

    Task
    -----
    I need to load two excel into two different tables in the same (Oracle) database and compare the same and need to give output as
    a)Modified records(Primary _Key_Field_Valu e, XL1 value(old value), XL2 value(New value)
    b)New(Inserted) records which are present in XL@ but not in XL1
    c)Old(Deleted) records which are present in XL! but not in XL2.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What do you have so far?

    Comment

    • vijaya hyd
      New Member
      • May 2013
      • 7

      #3
      Originally posted by Rabbit
      What do you have so far?
      I did not get your quextion.
      Let me know what things need to make it more clear to you to understand the problem. should I give sample data, which is of 50+ columns and above 300,000 records

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        I mean what have you done so far towards solving your problem. What code do you have? What steps have you taken? Have you at least imported the data from Excel to the database?

        Comment

        • vijaya hyd
          New Member
          • May 2013
          • 7

          #5
          I could able to save excels into two tables.
          I need to compare col1 of TableA to col1 of TableB, similarly 30+ columns I have to compare and if any change found, I need to Insert those changes in TableC
          TableC structre is like
          ID ColumnName TableA_Value TableB_Value
          1 Emp_Dept Accounts Admin
          1 Address XYZ ABC
          2 Sal 10000 12000
          Last edited by vijaya hyd; May 2 '13, 09:37 AM. Reason: ...

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            You already told us what your end goal is. You still haven't told me what you've done so far.

            Comment

            • vijaya hyd
              New Member
              • May 2013
              • 7

              #7
              Sincere apologies for not giving you clear picture of what I have done.
              Right now I am taking the inner join of the two tables and looping each column and checking each column value in both the tables and comparing the values, which is taking lot of time.

              Code:
              loop for rows starts
              loop for columns starts
              ...
              val1=select '||col1' from tableA where key_value='||_ID||'
              val2=select '||col1' from tableB where key_value='||_ID||'
              
              if(val1<>val2)
                  Insert into tableC with ChangedCoulmn Name and TableA_
              Value, TableB_value.
              ..
              loop for rows ends here
              loop for columns ends here
              Hope I made it. clear. As pl/sql code is in prod server I could not give the same.
              Last edited by Rabbit; May 2 '13, 04:47 PM. Reason: Please use code tags when posting code.

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                Please use code tags when posting code.

                It sounds like you're only talking about #1. That is a bit more involved than #2 and #3. Those are a lot simpler so let me get that out of the way quickly. #2 and #3 can be accomplished using outer joins and looking for the nulls.

                As for #1, if you're using Oracle 11g and above, you'll want to unpivot your 30+ columns. If you're using a prior version, you can use a series of union all queries to achieve the same effect.

                Once you've unpivoted each table, you can join the two on the id and column name and compare the two values.

                Comment

                • vijaya hyd
                  New Member
                  • May 2013
                  • 7

                  #9
                  Thank you very much for the quick response. As you have mentioned , #2 and #3 I have done using joins and I will try #1 with your suggestion and if possible can you provide a sample.

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    That depends on which version you have.

                    Comment

                    • vijaya hyd
                      New Member
                      • May 2013
                      • 7

                      #11
                      It is oracle 11g R2.
                      I feel happy if you can provide a sample as I am a newbie to oracle pl/sql

                      Thanks in advance

                      Comment

                      • Rabbit
                        Recognized Expert MVP
                        • Jan 2007
                        • 12517

                        #12
                        Here is oracle's documentation on the pivot and unpivot syntax: http://www.oracle-base.com/articles/...tors-11gr1.php.

                        You will want to use the examples in there to unpivot your two tables. That's the first step.

                        Comment

                        • vijaya hyd
                          New Member
                          • May 2013
                          • 7

                          #13
                          Thank you friend I will look into this and get back to you if required .
                          Thanks once again for the detailed info.

                          Comment

                          Working...