Solved

Oracle column differences like a UNIX "diff" command

Posted on 2011-03-24
8
516 Views
Last Modified: 2013-12-26
In an Oracle database, there are two columns in two different tables of the same type - VARCHAR2(4000). The columns are basically a pseudo code.  The columns contain lines of code with embedded line returns.

The need is to be able to determine the difference between the two columns, lines modified, new lines, and deleted lines.  The results becomes a basic UNIX command “diff” of the two columns.

The code needs to be able to report the differences on demand from a Visual Studio 2008 C# application.

Example:

Table 1 column:

--      02073 ALLTEL
NET_CYCLE_TXT            :=  'Changed - NETWORK IS BILLED ON A CURRENT CALENDAR MONTH' ;
NET_CRX_L1_CH            :=      5000.00;
NET_CRX_L2_CH            :=      4250.00;
NET_NET_L1_CH            :=        900.00;
NET_NET_L2_CH            :=      1850.00;
NET_TOT            :=      NET_CRX_L1_CH + NET_CRX_L2_CH + NET_NET_L1_CH + NET_NET_L2_CH;

--Special Message Text--
NET_SPBILL_3_TXT      := 'INSTALL/DISCONNECT DATE REFLECTED IN CHARGE LINE - CHARGES ARE PRORATED BASED ON DATE';

ZGD_NET            :=      NET_TOT;

Table 2 column:

--      02073 ALLTEL
NET_CYCLE_TXT            :=  'NETWORK IS BILLED ON A CURRENT CALENDAR MONTH' ;

NET_CRX_L1_CH            :=      4250.00;
NET_CRX_L2_CH            :=      4250.00;
NET_NET_L1_CH            :=        900.00;
NET_NET_L2_CH            :=      1850.00;
NET_EDT_L1_CH            :=      500.00;
NET_EDT_L2_CH            :=      1500.00;
NET_TOT      :=      NET_CRX_L1_CH + NET_CRX_L2_CH + NET_NET_L1_CH + NET_NET_L2_CH +           NET_EDT_L1_CH + NET_EDT_L2_CH;

--Special Message Text--
NET_SPBILL_3_TXT      := 'INSTALL/DISCONNECT DATE REFLECTED IN CHARGE LINE - CHARGES ARE PRORATED BASED ON DATE';

ZGD_NET            :=      NET_TOT;
0
Comment
Question by:dsjohndavid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 35209913

Forget about re-inventing the wheel and load the code into a source code / version control management software.

My 2c.
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 35210001

Or:

1) Use a 'split' function (lots available on Oracle forums) to separate the lines of the source varchar column and load the lines into an array.

2) Do the same for the target varchar you want to compare to.

3) compare both arrays and report the differences.

0
 

Author Comment

by:dsjohndavid
ID: 35215173
That is what I have done. The challenge comes when trying to determine if a line is new, deleted, or just modified between the one column and the other when the lines differ. Any suggestions?
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 35217994

Well....that's why I said you would be "re-inventing the wheel".

I tried it once and it's quite complex, whenever you find a different line, you have to check ahead in both sources for matching line(s) and decide if the line was added or removed. Most "diff" utilities report changes as delete/insert pairs.

Good luck!


0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 35218028

PS: Also you must decide if you are going to ignore differences due to characters in  "upper/lower case", the number of consecutive spaces (or tabs), empty lines, etc...

0
 
LVL 1

Accepted Solution

by:
tropically earned 500 total points
ID: 35300737

Is this a one time thing you're trying to do.

Other approaches other than using pl/sql.

Dump both columns into individual seperate files,
Use a diff tool that supports command line and output the diff to a third file.


0
 
LVL 62

Expert Comment

by:gheist
ID: 35501477
select d1,d2 from table where not (d1=d2)
0
 

Author Closing Comment

by:dsjohndavid
ID: 37066037
I did just this and used "WinMerge" to determine the differences.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to take different types of Oracle backups using RMAN.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question