Sie sind auf Seite 1von 8

WORKING IN OTHER ORACLE SCHEMAS

Author JP Vijaykumar
DATE 05-14-2010
MODIFIED 05-30-2010
The following sql commands are to be execute in veeksha's schema.

create table TEMP_VEEKSHA1(col1 number, col2 varchar2(20))


tablespace users;
create index temp_veeksha1_idx01 on TEMP_VEEKSHA1(COL1)
tablespace users;
Create or replace synonym temp_ramamohan for ramamohan.temp_ramamohan;
select * from temp_ramamohan;
create database link PROD
connect to scott identified by tiger
using 'PROD';
select sysdate from dual@prod;
alter table temp_veeksha1 rename column col1 to empno;
alter table temp_veeksha1 rename column col2 to ename;
rename temp_veeksha1 to temp_veeksha;
----------------------------------------------------------
As a dba, I can execute these sql commands in veeksha's schema
in any of the three methods.
Method 01
Setting the current schema to veeksha with
alter session set current_schema=veeksha;
and execute the sql commands.
Not all the sql commands can be executed in this way.
Method 02
Prefixing the schema owner veeksha
to all the objects referenced in these scripts
and execute the sql commands.
Not all the sql commands can be executed in this way.
Method 03
Connecting to the db as the schema owner veeksha
with Veeksha's password and execute the sql commands.
case 0310 I know the veeksha userid's password.
0311 I don't know veeksha userid's password with default profile.
0312 I don't know veeksha userid's password with non default profile.
Which method can help us execute all the above sql commands successfully?
--------------------------------------------------------
Executed these sql commands and setup the test environment:
drop user ramamohan cascade;
create user ramamohan identified by ramamohan account unlock
default tablespace users quota unlimited on users;
grant create session, resource to ramamohan;
create table ramamohan.temp_ramamohan(empno number, ename varchar2(10),hiredate
date)
tablespace users;
insert into ramamohan.temp_ramamohan values(1,'MAHALAXMI',to_date('11-MAY-1986',
'DD-MON-YYYY'));
commit;
drop user veeksha cascade;
create user veeksha identified by T3mp1e account unlock
default tablespace users quota unlimited on users;
grant create session, resource,create synonym,create database link to veeksha;
grant select on ramamohan.temp_ramamohan to veeksha;
For Method 03 - case 0312 - executed this command:
alter user veeksha profile apps_profile;
------------------------------------------------------------------------
Method 01
Set the current_schema to veeksha.
SQL> alter session set current_schema=veeksha;
Session altered.
SQL> create table TEMP_VEEKSHA1(col1 number, col2 varchar2(20))
tablespace users; 2
Table created.
SQL> create index temp_veeksha1_idx01 on TEMP_VEEKSHA1(COL1)
tablespace users; 2
Index created.
SQL> Create or replace synonym temp_ramamohan for ramamohan.temp_ramamohan;
Synonym created.
SQL> select * from temp_ramamohan;
EMPNO ENAME HIREDATE
---------- ---------- ---------
1 MAHALAXMI 11-MAY-86
SQL> create database link PROD
connect to scott identified by tiger
using 'PROD';
2 3 create database link PROD
*
ERROR at line 1:
ORA-01031: insufficient privileges

SQL> select sysdate from dual@prod;


select sysdate from dual@prod
*
ERROR at line 1:
ORA-02019: connection description for remote database not found

SQL> alter table temp_veeksha1 rename column col1 to empno;


Table altered.
SQL> alter table temp_veeksha1 rename column col2 to ename;
Table altered.
SQL> rename temp_veeksha1 to temp_veeksha;
rename temp_veeksha1 to temp_veeksha
*
ERROR at line 1:
ORA-03001: unimplemented feature
SQL> column owner format a10
column object_name format a20
column object_type format a20
select owner,object_name,object_type from dba_objects
where created > trunc(sysdate);
OWNER OBJECT_NAME OBJECT_TYPE
---------- -------------------- --------------------
RAMAMOHAN TEMP_RAMAMOHAN TABLE
VEEKSHA TEMP_VEEKSHA1 TABLE
VEEKSHA TEMP_RAMAMOHAN SYNONYM
VEEKSHA TEMP_VEEKSHA1_IDX01 INDEX

In Method 01, the private database link is not created,


temp_veeksha1 table is not renamed.
For renaming veeksha's table temp_veeksha1 use the following command:
alter table veeksha.temp_veeksha1 rename to temp_veeksha;
----------------------------------------------------------
Method 02
Edited the file prefixing veeksha to all the objects referenced in the script.

SQL> create table veeksha.TEMP_VEEKSHA1(col1 number, col2 varchar2(20))


tablespace users; 2
Table created.
SQL> create index veeksha.temp_veeksha1_idx01 on veeksha.TEMP_VEEKSHA1(COL1)
tablespace users; 2
Index created.
SQL> Create or replace synonym veeksha.temp_ramamohan for ramamohan.temp_ramamoh
an;
Synonym created.
SQL> select * from veeksha.temp_ramamohan;
EMPNO ENAME HIREDATE
---------- ---------- ---------
1 MAHALAXMI 11-MAY-86

SQL> create database link veeksha.PROD


connect to scott identified by tiger
using 'PROD'; 2 3
Database link created.
SQL> select sysdate from dual@veeksha.PROD;
SYSDATE
---------
25-APR-10
SQL> alter table veeksha.temp_veeksha1 rename column col1 to empno;
Table altered.
SQL> alter table veeksha.temp_veeksha1 rename column col2 to ename;
Table altered.
SQL> rename veeksha.temp_veeksha1 to veeksha.temp_veeksha;
rename veeksha.temp_veeksha1 to veeksha.temp_veeksha
*
ERROR at line 1:
ORA-01765: specifying table's owner name is not allowed

SQL> column owner format a10


column object_name format a20
column object_type format a20
select owner,object_name,object_type from dba_objects
where created > trunc(sysdate);
OWNER OBJECT_NAME OBJECT_TYPE
---------- -------------------- --------------------
RAMAMOHAN TEMP_RAMAMOHAN TABLE
VEEKSHA TEMP_VEEKSHA1 TABLE
VEEKSHA TEMP_RAMAMOHAN SYNONYM
VEEKSHA TEMP_VEEKSHA1_IDX01 INDEX
SYS VEEKSHA.PROD DATABASE LINK
In Method 02, only rename of temp_veeksha1 table failed.
Don't be misled, even the private database link also failed.
The private database link is not created in veeksha's schema,
but it was created in sys schema. Check the owner of the
database link VEEKSHA.PROD from the above command output.
For renaming veeksha's table temp_veeksha1 use the folloging command:
alter table veeksha.temp_veeksha1 rename to temp_veeksha;
--------------------------------------------------------
Method 03
Connecting as the schema owner and executing the scripts.
case 0310 I know the veeksha userid's password.
0311 I don't know veeksha userid's password with default profile.
0312 I don't know veeksha userid's password with non default profile.
Case 0310
SQL> connect veeksha/T3mp1e@dev
Connected.
SQL> create table TEMP_VEEKSHA1(col1 number, col2 varchar2(20))
tablespace users;
2
Table created.
SQL> create index temp_veeksha1_idx01 on TEMP_VEEKSHA1(COL1)
tablespace users;
2
Index created.
SQL> Create or replace synonym temp_ramamohan for ramamohan.temp_ramamohan;
Synonym created.
SQL> select * from temp_ramamohan;
EMPNO ENAME HIREDATE
---------- ---------- ---------
1 MAHALAXMI 11-MAY-86
SQL> create database link PROD
connect to scott identified by tiger
using 'PROD'; 2 3
Database link created.
SQL> select sysdate from dual@prod;
SYSDATE
---------
25-APR-10
SQL> alter table temp_veeksha1 rename column col1 to empno;
Table altered.
SQL> alter table temp_veeksha1 rename column col2 to ename;
Table altered.
SQL> rename temp_veeksha1 to temp_veeksha;
Table renamed.
/* This command also works:
alter table temp_veeksha1 rename to temp_veeksha; */
In Method 03, all the sql commands were executed successfully.
I could create a private database link and rename the table.
Out of the three above methods, Method 03 is the safest one.
But the problem is with maintaing the users and passwords.
SQL> connect /as sysdba
Connected.
SQL> column owner format a10
column object_name format a20
column object_type format a20
select owner,object_name,object_type from dba_objects
where created > trunc(sysdate);
OWNER OBJECT_NAME OBJECT_TYPE
---------- -------------------- --------------------
RAMAMOHAN TEMP_RAMAMOHAN TABLE
VEEKSHA TEMP_VEEKSHA TABLE
VEEKSHA TEMP_RAMAMOHAN SYNONYM
VEEKSHA TEMP_VEEKSHA1_IDX01 INDEX
VEEKSHA PROD DATABASE LINK
The same is verified from the dba_objects view.
Case 0311 is straight forward. I don't know user veeksha's password.
But the user veeksha is assigned with a default profile. I can change the users
password, connect as that user complete the task and safely reset the old
password to veeksha.
Case 0312 is somewhat different. When the user's profile is not default,
Chances are that the old password of the user can not be re-used.
In that case, first the profile is to be set to default, then
password is to be changed, connect back as the schema owner,re-set
the old password, Then connect as sysdba and reset the old profile back to the s
chema owner.
Pls test this script thoroughly in development dbs before using in production db
s.

SQL> set serverout on size 1000000


SQL> declare
2 begin
3 for c1 in (select username, password, profile from dba_users where usern
ame='VEEKSHA') loop
4
5 if (c1.profile = 'DEFAULT') then
6 dbms_output.put_line('alter user '||c1.username||' identified by '||c1.u
sername||';');
7 dbms_output.put_line('connect '||c1.username||'/'||c1.username);
8 dbms_output.put_line('alter user '||c1.username||' identified by values
'''||c1.password||''';');
9 else
10 dbms_output.put_line('alter user '||c1.username||' profile default;');
11 dbms_output.put_line('alter user '||c1.username||' identified by '||c1.u
sername||';');
12 dbms_output.put_line('connect '||c1.username||'/'||c1.username);
13 dbms_output.put_line('alter user '||c1.username||' identified by values
'''||c1.password||''';');
14 dbms_output.put_line('Open another session and login to the db as sysdba
');
15 dbms_output.put_line('connect /as sysdba');
16 dbms_output.put_line('alter user '||c1.username||' profile '||c1.profile
||';');
17 end if;
18 end loop;
19 end;
20 /
alter user VEEKSHA profile default;
alter user VEEKSHA identified by VEEKSHA;
connect VEEKSHA/VEEKSHA
alter user VEEKSHA identified by values 'B07C760EEC2D9A85';
Open another session and login to the db as sysdba
connect /as sysdba
alter user VEEKSHA profile apps_profile;
PL/SQL procedure successfully completed.
In summary, as a dba, you can perform most of the tasks in third party schemas.
With exception of a few tasks. Sometimes, if the schema owner is not prefixed
in the object creation scripts, those objects will be created in your currently
logged in schema.
Happly scripting.

Pls note in Oracle 11g, dba_users is not storing users' passwords.


Pls join user$ with dba_users in the above procedure, to get the user's password
.
****************************PERSONAL NOTES**************************************
***
SQL> create user jp identified by jp account unlock;
User created.
SQL> grant create session to jp;
Grant succeeded.
SQL> grant resource to jp;
Grant succeeded.
SQL> alter user jp quota unlimited on users;
User altered.
SQL> create table jp.temp_jp(col1 number) tablespace users;
Table created.
SQL> alter table jp.temp_jp rename to temp_jp2;
Table altered.
SQL> desc jp.temp_jp2;
Name Null? Typ

Also as a DBA, you can not drop a private database link in other's schema.
You need to connect as that schema owner to drop a private database link.
References:
http://laurentschneider.com/wordpress/2007/08/the-password-is-not-longer-display
ed-in-dba_userspassword.html
http://www.red-database-security.com/whitepaper/oracle_passwords.html
http://askdba.org/weblog/2008/11/how-to-changerestore-user-password-in-11g/

Das könnte Ihnen auch gefallen