Solved

Oracle column differences like a UNIX "diff" command

Posted on 2011-03-24
8
475 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
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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 61

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Oracle data into XML document 2 59
report returning null 21 80
ORA-12560: TNS:protocol adapter error 8 87
Schema creation in Oracle12c 6 39
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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 how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now