Developers have a requirement to move all objects in a schema to another shema. After thinking about it, simply change the schema name? In this way, you do not need to move the data. You are prepared to directly change the data using DDL statements:
- Alter UserScott renameToScott2;
This statement was not found at all. After I checked it online, I found that Oracle itself did not provide this function, but there was a data dictionary table: user $, all users in this table can directly update the table and try to change it. It is quite useful and the implementation is as follows:
- SQL>Desc User$;-- View the table structure www.bkjia.com
- NameNull? Type
- ---------------------------------------------------------------
- USER#NOT NULLNUMBER
- NAMENOT NULLVARCHAR2 (30)
- TYPE #NOT NULLNUMBER
- PASSWORDVARCHAR2 (30)
- DATATS #NOT NULLNUMBER
- TEMPTS #NOT NULLNUMBER
- CTIMENOT NULL DATE
- PTIMEDATE
- EXPTIMEDATE
- LTIMEDATE
- RESOURCE $NOT NULLNUMBER
- AUDIT $ VARCHAR2 (38)
- DEFROLENOT NULLNUMBER
- DEFGRP # NUMBER
- DEFGRP_SEQ # NUMBER
- ASTATUSNOT NULLNUMBER
- LCOUNTNOT NULLNUMBER
- DEFSCHCLASS VARCHAR2 (30)
- EXT_USERNAME VARCHAR2 (4000)
- SPARE1 NUMBER
- SPARE2 NUMBER
- SPARE3 NUMBER
- SPARE4 VARCHAR2 (1000)
- SPARE5 VARCHAR2 (1000)
- SPARE6DATE
- SQL>Select User#,Name From User$Where Name='Scott';-- Find the user to change
- USER#NAME
- ----------------------------------------
- 84 SCOTT
- SQL>Select Count(*)FromScott. emp;
- COUNT(*)
- ----------
- 14
- SQL>Update User$Set Name='Scott2' Where User# = 84;-- Change User Name
- 1 row updated.
- SQL>Commit;-- Submit www.bkjia.com
- CommitComplete.
- SQL>Select Count(*)FromScott. emp;
- COUNT(*)
- ----------
- 14
- SQL>AlterSystemCheckpoint;
- System altered.
- SQL>Select Count(*)FromScott. emp;
- COUNT(*)
- ----------
- 14
- SQL>AlterSystem flush shared_pool;-- Refresh shared_pool
- System altered.
- SQL>Select Count(*)FromScott. emp;
- Select Count(*)FromScott. emp
- *
- ERRORAtLine 1:
- ORA-00942:Table Or ViewDoesNotExist
- SQL>Select Count(*)FromScott2.emp;-- Changed successfully
- COUNT(*)
- ----------
- 14