Home » SQL & PL/SQL » SQL & PL/SQL » Unique hash based on user database objects. (Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production)
Unique hash based on user database objects. [message #643927] Wed, 21 October 2015 18:09 Go to next message
tmcallister
Messages: 107
Registered: December 2007
Senior Member
I'd like to create a unique hash for database schema objects.

Something along of lines of the following:

WITH tabcols AS (SELECT SUBSTR(TRIM(table_name || column_name || data_type || data_length || data_precision || data_scale || nullable || column_id), 1, 4) tabcol FROM user_tab_columns),
     hashexpr AS (SELECT LISTAGG(tabcol) WITHIN GROUP (ORDER BY tabcol) expr FROM tabcols)
SELECT   ORA_HASH(expr) hash
FROM     hashexpr

Note: depending on this size of your database you may need to adjust the substr size to prevent ORA-1489

Problems:
(1) I obviously don't want to use the substr command.
(2) I'm not including all objects. Packages, procedures, functions, indexes, keys, constraints, etc should all be included.

It occurs to me that someone else has probably wanted to do this before, and I probably don't need to reinvent the wheel here. If there is an easy shortcut or already completed solution I'd love to hear it; otherwise I'll start progressing using clobs and/or plsql; etc.

[Updated on: Wed, 21 October 2015 18:14]

Report message to a moderator

Re: Unique hash based on user database objects. [message #643928 is a reply to message #643927] Wed, 21 October 2015 19:32 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
What problem are you trying to solve?

What advantage will the hash have over USER_TAB_COLUMNS view?
Re: Unique hash based on user database objects. [message #643929 is a reply to message #643927] Thu, 22 October 2015 01:05 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

What is your actual need?

Re: Unique hash based on user database objects. [message #643937 is a reply to message #643929] Thu, 22 October 2015 09:34 Go to previous messageGo to next message
tmcallister
Messages: 107
Registered: December 2007
Senior Member
I'm trying to create a unique hash, in order to give a each specific representation of a schema a type of version number and to easily identify any modifications by comparing that single value.

My idea for doing that is to concatenate all the tables, columns, functions (including code), procedures, packages, triggers, sequences, etc together and hashing them.

[Updated on: Thu, 22 October 2015 09:50]

Report message to a moderator

Re: Unique hash based on user database objects. [message #643938 is a reply to message #643937] Thu, 22 October 2015 09:37 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
tmcallister wrote on Thu, 22 October 2015 07:34
I'm trying to create a unique hash, in order to give a each specific representation of a schema a type of version number and to easily identify any modifications by comparing that single value.


such as USER_OBJECTS.LAST_DDL
Re: Unique hash based on user database objects. [message #643939 is a reply to message #643938] Thu, 22 October 2015 09:41 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Laughing

Re: Unique hash based on user database objects. [message #643946 is a reply to message #643938] Thu, 22 October 2015 16:33 Go to previous messageGo to next message
tmcallister
Messages: 107
Registered: December 2007
Senior Member
BlackSwan wrote on Thu, 22 October 2015 08:37
tmcallister wrote on Thu, 22 October 2015 07:34
I'm trying to create a unique hash, in order to give a each specific representation of a schema a type of version number and to easily identify any modifications by comparing that single value.


such as USER_OBJECTS.LAST_DDL


I see LAST_DDL_TIME? I don't think either would satisfy my needs.
Re: Unique hash based on user database objects. [message #643947 is a reply to message #643946] Thu, 22 October 2015 19:23 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
> easily identify any modifications by comparing that single value.
can be done by using USER_OBJECTS.LAST_DDL
Previous Topic: get the remote DB instance name
Next Topic: Need answer for below block
Goto Forum:
  


Current Time: Fri Jul 17 22:06:14 CDT 2026