Solved

Oracle column differences like a UNIX "diff" command

Posted on 2011-03-24
8
457 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

707 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

14 Experts available now in Live!

Get 1:1 Help Now