How to change schema name? - oracle

I have created a user:
CREATE USER gds_map
IDENTIFIED BY gds_map;
And now I need to change a name. I tried to update or find other way but have not found nothing yet.
I will be glad of any hint.

If you want to modify a schema's name,you should have the preveledegs on USER$
1. Get Id of a schema's name
SQL> select user#,NAME from SYS.user$ WHERE NAME='TEST';
USER# NAME
---------- ------------------------------
*93* TEST
2. modify the schema's name
SQL> UPDATE USER$ SET NAME='NEW_SCHEMA_NAME' WHERE USER#=93;
3. finished commit
SQL> COMMIT;
4. modify the system SCN
SQL> ALTER SYSTEM CHECKPOINT;
5.Then refresh shared_pool
SQL> ALTER SYSTEM FLUSH SHARED_POOL;
6. Modify the new schema's password
SQL> ALTER USER new_schema IDENTIFIED BY new_pass;

You can't (at least not in a supported or vaguely responsible way). You'd need to create a new user with the new username and drop the old user.

No methods exists to rename an oracle schema.
Try,
1-Create new schema
2-Export the old schema,
$exp owner=test2
3-Import old schema to new schema,
$imp fromuser=test2 touser=newuser_name

do this
1- login as sys
2- execute this:
update sys.user$
set name= 'new_name'
where name = 'old_name';
3- then restart the database

I've needed to do this so often that I even wrote an article about this topic
The workaround that I use is to "clone" the user to the same DB with a different name, using loopback dblink.
It's very fast and in the end, after a successful checkup, you can drop the old schema.
Check it here: http://www.dbarj.com.br/en/2014/11/rename-schema-oracle-11g-loopback-dblink/
Regards,
Rodrigo Jorge

In oracle database you cannot rename your username but you can change your password.
alter user USER_NAME identified by <enter_new_password>;

Related

Oracle XE audit_trail not saving for all users

I enabled auditing on my Oracle XE server via the following run by the sys user:
SQL> ALTER SYSTEM SET audit_sys_operations=true SCOPE=spfile;
SQL> ALTER SYSTEM SET audit_trail=XML,EXTENDED SCOPE=spfile;
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP
When I run queries as the sys user, an xml file records the queries in the default location (e.g., /u01/app/oracle/admin/XE/adump/xe_ora_2339_1.xml). However, if I run a query as a different user (e.g., test_user), no updates occur in any of the files in the adump directory.
I've confirmed that the parameter is set for the test_user:
SQL> show parameter audit;
NAME TYPE VALUE
------------------------ ------- ------------------------------
audit_file_dest string /u01/app/oracle/admin/XE/adump
audit_sys_operations boolean TRUE
audit_syslog_level string
audit_trail string XML, EXTENDED
I also tried restarting my sqlplus session (i.e., reconnecting with the test_user), as well as disabling audit_sys_operations, and the issue remains.
Version info: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production (via this docker image).
My issue was that, in addition to enabling auditing, I also needed to specify what to audit with the AUDIT command. In my case, I wanted everything, so I added the following (commands mentioned in this tutorial):
SQL> AUDIT ALL; # note: it seems like the next two statements would be included with "all", but I didn't verify this.
SQL> AUDIT SELECT TABLE, UPDATE TABLE, INSERT TABLE, DELETE TABLE;
SQL> AUDIT EXECUTE PROCEDURE;
Note that with AUDIT_TRAIL=XML,EXTENDED (and maybe all the file-based auditing settings?), it looks there is some buffering of writing the XML file, as I didn't get a query showing up until my test user disconnected, so if you are missing a log entry, try logging the user out to see if it shows up.

oracle table entry does not exist

while installing sap on 3 tiered architecture, I need to install database instance (oracle) and central instance(sap) and two different machines.
after completing database install and proceeding with central instance installation, the setup is trying to access a table and fails with following error
SELECT USERID, PASSWD FROM
SAPUSER WHERE USERID IN (:A0, :A1)
OCI-call failed with
-1=OCI_ERROR SQL error 942: 'ORA-00942: table or view does not exist'
*** ERROR => ORA-942 when
accessing table SAPUSER
so I checked and found out that two cases are possible
Table does not exist or
User has no access rights to this Table
next I checked for table, and found an entry in dba_tables,
SQL> select owner from dba_tables where table_name='SAPUSER';
OWNER
------------------------------
OPS$E64ADM
but when trying to fetch data from it using select query
SQL> select * from SAPUSER;
select * from SAPUSER
*
ERROR at line 1:
ORA-00942: table or view does not exist
now I am confused, whether the table is available or not. what is the reason for this and how can it be resolved?
It depends on where you are accesing the object from,
check to see which user you are logged in as
SQL> SHOW USER
This will show which user you are logged in as,
if you are in OPS$E64ADM, the directly query using
SQL> select * from SAPUSER;
if show user show anyother user you need privilege to access it from other users, can ask dba or if you have access then run,
SQL> grant select on OPS$E64ADM.SAPUSER to username; -- the username from which you want to access the table;
then, you can acces from the other user , using,
SQL> select * from OPS$E64ADM.SAPUSER
who are you signed in as? unless it's the owner of the table you will need to change your code to include the owner ie.
select * from OPS$E64ADM.SAPUSER

Unable to use synonym of functions, procedures or seq in Oracle

I have created synonyms for functions/proc/seq in userid YYY from user id XXX.
create SYNONYM my_seq FOR XXX.my_seq
When I try to use the seq in user YYY, I am getting following error :
ORA-00942: table or view does not exist
and with functions : ORA-00904: : invalid identifier
Please let me know where I am doing wrong.
I am going to demonstrate with a simple example. I have two schemas on one server. Schema1 and Schema2.
I logon to Schema1 and run the script below.
-- Create sequence
create sequence originalSeq
minvalue 1
maxvalue 999999999999999999999999
start with 1
increment by 10
cache 20;
GRANT SELECT ON originalSeq TO SCHEMA2;
Then I logon to Schema2 and run the following script.
create or replace synonym pointertooriginalsreq
for SCHEMA1.originalSeq;
select pointertooriginalsreq.nextval from dual
this should work in all versions of Oracle 8.1.7 upwards. Please let me know if you're still facing a problem.
You have to provide grants from XXX user:
GRANT SELECT ON my_seq TO YYY;

Oracle SELECT granted but still can't access table across users

Can any one see what's wrong with this:
User ABC:
create table def.something (
id number,
ref number references def.anotherTable(id)
);
create role ROUser;
grant select on def.something to ROUser;
grant ROUser to ghi;
User DEF:
select * from something;
...
X rows returned
User GHI:
select * from def.something;
ORA-00942: table or view does not exist
Is the fact that there's a foreign key, that GHI doesn't have access to, on def.something the problem?
EDIT I've just tried this again on another server and it works fine (i.e., as expected). Not entirely sure what's going on here, but I think it may have something to do with some error on my part... As such, I'm voting to close the question.
You are most probably running that SELECT statement in PL/SQL block? In PL/SQL, priviliges granted through roles are not recognized. Try adding direct SELECT privilege on that table and see if it works.

Oracle Syntax for Creating Database Link Owned by Another User

The typical syntax for creating a db link is as follows:
create database link remote_db_link
connect to remote_user
identified by remote_password
using 'remote_db'
But I'd like my DB link owned by another account after it's created. Is there a way to do this?
The following does NOT work:
create database link anotheruser.remote_db_link
connect to remote_user
identified by remote_password
using 'remote_db'
Sathya is correct, in that the CREATE DATABASE LINK syntax does not allow creating a database link in another schema. HOWEVER...
WORKAROUND
It IS possible to create a database link in another user's schema, as long as anotheruser has CREATE DATABASE LINK privilege, and the user you are connected as has CREATE ANY PROCEDURE privilege.
Here's the workaround I use:
create procedure anotheruser."tmp_doit_200906121431"
is
begin
execute immediate '
create database link remote_db_link
connect to remote_user
identified by remote_password
using ''remote_db'' ';
end;
/
begin
anotheruser."tmp_doit_200906121431";
end;
/
drop procedure anotheruser."tmp_doit_200906121431"
/
Let's unwind that. First, I create a procedure in the anotherusers's schema; this procedure contains the CREATE DATABASE LINK statement that I want to run.
When the procedure is executed, it runs as the owner of the procedure, such that the CREATE DATABASE LINK statement is executed by anotheruser.
The name of the procedure is not important, except that I need to make sure that it doesn't conflict with any existing object name. I use lowercase letters (enclosing the procedure name in double quotes), using "tmp" to mark this object as "temporary", and using the current yyyymmddhh24miss as the part of the procedure name. (I usually run a query of DBA_OBJECTS to check that a matching object_name does not exist.)
For a "one-off" type admin function, this is a viable workaround. I prefer this to the other alternative: saving the anotheruser's password, changing the password, connecting as the user, and resetting anotheruser's password back to the saved.)
Restrictions on DBLinks - You cannot create a database link in another user's schema, and you cannot qualify dblink with the name of a schema.
AS a sys user you can view all db links in SYS.DBA_DB_LINKS view.
That view use link$ and user$ table.
You can create new dblink as usually and it show at link$ table. Then change owner (use id from user$). commit. Done.

Resources