How to compare column name of a schema with other schema's column name [message #572673] |
Sat, 15 December 2012 07:18 |
nehhaverma
Messages: 34 Registered: September 2009 Location: JAIPUR
|
Member |
|
|
Hello
I have a standard schema named ABC and 600 more schema's over there in my database.They all has same table name and column name as on standard schema. But in some tables number of columns varying. So I need to compare all schemas with my standard schemas column name. I create below script but it is generating output in infinite loop. Kindly help me I am not good in plsql.
SET SERVEROUTPUT ON
DECLARE
V_COLS VARCHAR2(20);
BEGIN
FOR CUR_CCD IN(SELECT DISTINCT TABLE_NAME,OWNER FROM ALL_TABLES
WHERE OWNER LIKE 'CCD_MAIN'
)
LOOP
FOR CUR_USR IN(SELECT DISTINCT TABLE_NAME, OWNER
FROM ALL_TABLES
AND OWNER NOT LIKE 'CCD_MAIN'
ORDER BY 2)
LOOP
FOR CUR_COL IN (SELECT DISTINCT COLUMN_NAME FROM
(SELECT DISTINCT COLUMN_NAME FROM
ALL_TAB_COLUMNS
WHERE TABLE_NAME = CUR_CCD.TABLE_NAME
AND OWNER=CUR_CCD.OWNER
MINUS
SELECT DISTINCT COLUMN_NAME FROM
ALL_TAB_COLUMNS
WHERE TABLE_NAME = CUR_CCD.TABLE_NAME
AND OWNER =CUR_USR.OWNER))
LOOP
DBMS_OUTPUT.PUT_LINE(CUR_USR.OWNER||' : '||CUR_CCD.TABLE_NAME||' :'||CUR_COL.COLUMN_NAME);
END LOOP;
END LOOP;
END LOOP;
END;
/
Thanks
Neha
[mod-edit: code tags added by bb; next time please add them yourself]
[Updated on: Sat, 15 December 2012 10:14] by Moderator Report message to a moderator
|
|
|
|
Re: How to compare column name of a schema with other schema's column name [message #572679 is a reply to message #572673] |
Sat, 15 December 2012 11:25 |
|
Barbara Boehmer
Messages: 9104 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
The following contains minimal corrections and simplification. You could probably simplify it further or even do it all with just SQL, without PL/SQL.
SET SERVEROUTPUT ON
BEGIN
FOR cur_tab IN
(SELECT DISTINCT ccd.owner ccd_owner, ccd.table_name ccd_table_name, usr.owner usr_owner
FROM all_tables ccd, all_tables usr
WHERE ccd.table_name = usr.table_name
AND ccd.owner != usr.owner
AND ccd.owner = 'CCD_MAIN'
ORDER BY ccd.table_name, usr.owner)
LOOP
FOR cur_col IN
(SELECT column_name
FROM all_tab_columns
WHERE owner = cur_tab.ccd_owner
AND table_name = cur_tab.ccd_table_name
MINUS
SELECT column_name
FROM all_tab_columns
WHERE owner = cur_tab.usr_owner
AND table_name = cur_tab.ccd_table_name)
LOOP
DBMS_OUTPUT.PUT_LINE
(cur_tab.usr_owner || ' : ' ||
cur_tab.ccd_table_name || ' :' ||
cur_col.column_name);
END LOOP;
END LOOP;
END;
/
[Updated on: Sat, 15 December 2012 11:49] Report message to a moderator
|
|
|
|
|
|
Re: How to compare column name of a schema with other schema's column name [message #572829 is a reply to message #572689] |
Tue, 18 December 2012 01:08 |
nehhaverma
Messages: 34 Registered: September 2009 Location: JAIPUR
|
Member |
|
|
Thanks to all.
I chnaged my code.
SET SERVEROUTPUT ON
DECLARE
V_COLS VARCHAR2(20);
BEGIN
FOR CUR_CCD IN(SELECT DISTINCT TABLE_NAME,OWNER
FROM ALL_TABLES
WHERE OWNER LIKE 'CCD_MAIN')
LOOP
FOR CUR_USR IN(SELECT DISTINCT TABLE_NAME, OWNER
FROM ALL_TABLES
WHERE OWNER LIKE '%_MAIN'
and OWNER NOT in ('CCD_MAIN','SYS','SYSTEM','OUTLN','SCOTT')
and table_name = cur_ccd.table_name
ORDER BY 2)
LOOP
FOR CUR_COL IN (SELECT DISTINCT COLUMN_NAME FROM
(SELECT DISTINCT COLUMN_NAME
FROM ALL_TAB_COLUMNS
WHERE TABLE_NAME = CUR_CCD.TABLE_NAME
AND OWNER=CUR_CCD.OWNER
MINUS
SELECT DISTINCT COLUMN_NAME
FROM ALL_TAB_COLUMNS
WHERE TABLE_NAME = CUR_CCD.TABLE_NAME
AND OWNER =CUR_USR.OWNER))
LOOP
DBMS_OUTPUT.PUT_LINE(CUR_USR.OWNER||' : '||CUR_CCD.TABLE_NAME||' : '||CUR_COL.COLUMN_NAME);
END LOOP;
END LOOP;
END LOOP;
END;
/
Thanks & Regards/
Neha Verma
*BlackSwan added {code} tags. do so yourself in the future!
[Updated on: Tue, 18 December 2012 08:47] by Moderator Report message to a moderator
|
|
|
|
Re: How to compare column name of a schema with other schema's column name [message #572949 is a reply to message #572905] |
Tue, 18 December 2012 21:48 |
|
in case if i want to do the same column comparisions for same table lying in two different databases, then how can i compare.lets us there is one database user rakdb which has table om_item with field item_code varchar2(12),item_name varchar2(12), item_long_name varchar2(20) but in another database user raklive the same table exists with one column less, om_item with fields item_code varchar2(12),item_long_name varchar2(20).How to list out them.
|
|
|
|
Re: How to compare column name of a schema with other schema's column name [message #572951 is a reply to message #572950] |
Tue, 18 December 2012 22:18 |
|
Thanks mam for the prompt response , i read that article which you referred but there is one small confusion there are two options
1. do i need to create a db link and compare the user,table,column
2. do i need to import that schema user to the existing one and then compare
Actually i have to go with option a since both the user names on different database are same, like db1 have rakdb and db2 also have rakdb.Can you please suggest me how to create this dblink and do the comparision.
|
|
|
|
Re: How to compare column name of a schema with other schema's column name [message #572953 is a reply to message #572952] |
Tue, 18 December 2012 22:35 |
|
thanks very much , i will search for this in the documentation and will compare the columns , is there a way to find out differences at procedure/triggers/packages level to know whether they have been modified or not just like tables.Actually there is one problem basically we are facing , we are having two databases one at our site called raklive with user rakdb and another at remote site with another database jedlive with user jeddb but objects in both the databases are same , sometimes at our headoffice that is jedlive does some programming and they fail to intimate us about the changes and so we need to compare everytime, i have two queries and i need your goodself help on this.
1.I need to update the changes whatever done there to be done here using some standard method.
2.There is one table om_item where they are inserting records on daily basis and the user there he creates insert statments using toad and then ships us to run on out server to insert those records, can we automate this.
|
|
|
|
|
Re: How to compare column name of a schema with other schema's column name [message #573056 is a reply to message #572953] |
Thu, 20 December 2012 06:40 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
arif_md2009 wrote on Wed, 19 December 2012 04:35thanks very much , i will search for this in the documentation and will compare the columns , is there a way to find out differences at procedure/triggers/packages level to know whether they have been modified or not just like tables.Actually there is one problem basically we are facing , we are having two databases one at our site called raklive with user rakdb and another at remote site with another database jedlive with user jeddb but objects in both the databases are same , sometimes at our headoffice that is jedlive does some programming and they fail to intimate us about the changes and so we need to compare everytime, i have two queries and i need your goodself help on this.
1.I need to update the changes whatever done there to be done here using some standard method.
2.There is one table om_item where they are inserting records on daily basis and the user there he creates insert statments using toad and then ships us to run on out server to insert those records, can we automate this.
Do you not have source control? Cause that would fix all these issues if used properly.
|
|
|
|