Home » RDBMS Server » Server Administration » Can i update the TABLE_OWNER
Can i update the TABLE_OWNER [message #181512] Mon, 10 July 2006 06:27 Go to next message
sreehari
Messages: 101
Registered: May 2006
Senior Member
Hi all

Can i update the TABLE_OWNER in user_synonyms to actual owner of
the schema..since all these synonyms were imported from different schema...so that i can query those synonyms..

Thanks in advance..

Re: Can i update the TABLE_OWNER [message #181514 is a reply to message #181512] Mon, 10 July 2006 06:35 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Never directly update any datadictionary object.
Re: Can i update the TABLE_OWNER [message #181516 is a reply to message #181514] Mon, 10 July 2006 06:43 Go to previous messageGo to next message
sreehari
Messages: 101
Registered: May 2006
Senior Member
Ok..but i will explain my scenario

I have a database schema I1RB which has synonyms based on the schema I1PB in the same database 'POETICDB'.

what i did is..i exported these two schemas in the same database
with the different schema names I1PB2,I1RB2..

Now..when i try to access the synonyms in I1RB2. i am getting the error like table/view does not exist..

becasue..the owner_name for those synonyms is still I1PB..

How can i reslove this issue..

Help on this is greatly appreciated...

Thank u


in the database POETICDB

Re: Can i update the TABLE_OWNER [message #181535 is a reply to message #181516] Mon, 10 July 2006 07:47 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
You exported two schemas and imported them individually.
So I1RB2 is an exact copy of I1RB, where the TABLE_OWNER is still point to I1PB.
So I1RB2 synonym has the table_owner as I1PB.
You need to recreate the synonym for I1RB2 ( so that it look into I1PB2, instead of I1PB).

Applying a similar example,
I am logged in as user TEST.
The synonym will show table_owner to be as SCOTT.
If i export and import TEST into Test2, and Scott into Another_scott, still test2 will be looking into SCOTT.
So You need to recreate the synonym.
To do so, i am extracting the DDL of the synonym in test.
This simple script create the ddl.
I will Spool the output. and run against test2.
Before that, i should also make sure
-test2 can query the object in another_scott ( grant select priv)
-drop the existing,invalid synonym
test@9i > show user
USER is "TEST"

test@9i > select synonym_name,table_owner,table_name from user_synonyms;

SYNONYM_NAME                   TABLE_OWNER                    TABLE_NAME
------------------------------ ------------------------------ ------------------------------
SYN_EMP                        SCOTT                          EMP

test@9i > get get_ddl_synonym.sql
  1  set long 500000
  2  set linesize 1000
  3  SET HEAD off
  4  set trimspool on
  5  set verify off
  6  column XXXX format a300
  7  SELECT
  8  replace(replace((DBMS_METADATA.GET_DDL('SYNONYM',D.SYNONYM_NAME))||';','"TEST".','"TEST2".'),'"SCOTT".','"ANOTHER_SCOTT".')
  9  FROM user_synonyms D;
 10* set head on;
test@9i > @get_ddl_synonym.sql


  CREATE SYNONYM "TEST2"."SYN_EMP" FOR "ANOTHER_SCOTT"."EMP"
 ;


I used DBMS_METADATA.
You can use show=y option in import or whatever.
use Any GUI tool like toad to extract DDL and manually edit.
It is upto you.

[Updated on: Mon, 10 July 2006 07:48]

Report message to a moderator

Re: Can i update the TABLE_OWNER [message #181759 is a reply to message #181535] Tue, 11 July 2006 07:56 Go to previous message
saadatahmad
Messages: 452
Registered: March 2005
Location: Germany/Paderborn
Senior Member

hi,
I have created this script to change the user for all the synonyms in the current schema.
Run this script in Sqlplus and it'll ask you for the username.
Give the user name in single quotes and your synonyms will be replaced with the new username.
--THIS SCRIPS IS USED TO CREATE OR REPLACE ALL THE SYNONYMS IN THE CURRENT SCHEMA

--GIVE THE USERNAME AT THE PROMPT


DECLARE

 v_syn_name VARCHAR2(50);

 v_table_name VARCHAR2(50);

 v_table_owner VARCHAR2(10);

 v_sql VARCHAR2(200);

CURSOR c1 IS
 SELECT synonym_name, table_name, table_owner

 FROM user_synonyms;

 c2 c1%ROWTYPE;

BEGIN

 OPEN c1;

 LOOP FETCH c1 INTO c2;

     EXIT WHEN c1%NOTFOUND;

 v_syn_name := c2.synonym_name;

 v_table_name := c2.table_name;

 v_table_owner := C2.table_owner;

 v_sql := 'CREATE OR REPLACE SYNONYM '||v_syn_name||' FOR '||&user_name||'.'||v_table_name;
 
 EXECUTE IMMEDIATE(v_sql);

 END LOOP;

 DBMS_OUTPUT.PUT_LINE('Records processed : '||C1%ROWCOUNT);

 CLOSE c1;

END;


Hope this will also be help.

regards,
Saadat Ahmad
Previous Topic: moving table from one scheme to another
Next Topic: ora-01078 and ora-00109??
Goto Forum:
  


Current Time: Fri Sep 20 10:17:57 CDT 2024