Skip to Main Content
  • Questions
  • Spot the diffs between two database schemas inside SQL and PL/SQL code

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, José Laurindo.

Asked: June 20, 2018 - 1:01 pm UTC

Last updated: June 26, 2018 - 3:07 am UTC

Version: 11.2.0.4 SE

Viewed 1000+ times

You Asked

Hi : I have two Oracle databases (say, PROD and TEST), and in a given schema (present in both DBs) I must assure that the same SQL code (inside views) and/or PL/SQL code (triggers, procs, funcs, packages) exists, disconsidering the non-functional diffs (ie, line breaks, comments, white spaces, etc).
To do so, I was thinking about to use DBMS_METADATA with the beautifier option : it would work ?

Regards,

Chiappa

and Connor said...

I wouldn't reinvent the wheel. I'd just fire up SQL Developer and run Tools => Database Diff.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

How about the non-functional diffs ?

J. Laurindo Chiappa, June 25, 2018 - 11:51 am UTC

Yes, but how about the non-functional diffs such like line breaks, upper/lowercase itens, white spaces and alike ? How I could tell to SQL DEVELOPER ignore such differences in the comparision ?

Regards,

J. Chiappa

P.S.: just to add, when I spoke in DBMS_METADATA I was thinking in the lines of https://stackoverflow.com/questions/39911386/sql-regex-challenge-puzzle-how-to-remove-comments-from-sql-code-by-using-sql-q - of course, I would change the regex manipulations to take account of white spaces and upper/lowercases : if some option exists inside SQL DEVELOPER to get the same results please tell us...
Connor McDonald
June 26, 2018 - 3:07 am UTC

I'm pretty sure SQL Dev can't do that, and its a much harder job that it might seem.

Take the simple example of case-insensitivity

declare xxx varchar2(10) := 'Hello';
declare XXX varchar2(10) := 'Hello';

and equivalent, but

declare "xxx" varchar2(10) := 'Hello';
declare XXX varchar2(10) := 'Hello';

are not. Neither is:

declare xxx varchar2(10) := 'Hello';
declare xxx varchar2(10) := 'hello';

Similarly...

declare xxx varchar(10) := 'Hello';
declare xxx varchar2(10) := 'Hello';

are equivalent ... but should we highlight it as a difference?

I'm not saying it's not doable - I'm just saying it is not the same as simply setting the "ignore case" flag and things will be all rosy.


Yes, difficulties...

J. Laurindo Chiappa, June 26, 2018 - 1:02 pm UTC

Quoted strings diffs must be considered differences, but Yes, it´s not a simple logic...
SQL DEVELOPER have some internal facilities/resources to do it, for sure : for example, if I set in the code formatting options Identifiers case and Keywords case to UPPER (menu Tools, item Preferences, then inside Code Editor option Format) I will get the desired effect , ie, change my text :

declare
xxx varchar2(10) := 'Hello';
begin
XXX := 'ABC';
END;

DECLARE
XXX VARCHAR2(10) := 'hello';
Begin
xxx := 'xyz';
END;


to :


DECLARE
XXX VARCHAR(10) := 'Hello';
BEGIN
XXX := 'ABC';
END;

DECLARE
XXX VARCHAR2(10) := 'hello';
BEGIN
XXX := 'xyz';
END;

"escaping"/disconsidering the quoted strings as desired... But I was totally unable to use this features inside Code Comparision, and other necessities (such as remove extra whitespaces and linebreaks) were not found (by me) in the Code Format and/or Code Comparision options : due to this I opted for 'manual' procedures, such as extract the code via DBMS_METADATA and manipulate it with regexp, string functions and alike...
If really the task can´t be done inside SQL DEVELOPER, I will need to write something by myself, I think... But let me say thank you for confirming it...

Regards,

Chiappa

More to Explore

Administration

Need more information on Administration? Check out the Administrators guide for the Oracle Database