How to change the schema or user name in Oracle

Source: Internet
Author: User

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:

  1. 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:

  1. SQL>Desc User$;-- View the table structure www.bkjia.com
  2.  NameNull? Type
  3.  ---------------------------------------------------------------
  4.  USER#NOT NULLNUMBER
  5.  NAMENOT NULLVARCHAR2 (30)
  6. TYPE #NOT NULLNUMBER
  7.  PASSWORDVARCHAR2 (30)
  8. DATATS #NOT NULLNUMBER
  9. TEMPTS #NOT NULLNUMBER
  10. CTIMENOT NULL DATE
  11. PTIMEDATE
  12. EXPTIMEDATE
  13. LTIMEDATE
  14. RESOURCE $NOT NULLNUMBER
  15. AUDIT $ VARCHAR2 (38)
  16. DEFROLENOT NULLNUMBER
  17. DEFGRP # NUMBER
  18. DEFGRP_SEQ # NUMBER
  19. ASTATUSNOT NULLNUMBER
  20. LCOUNTNOT NULLNUMBER
  21. DEFSCHCLASS VARCHAR2 (30)
  22. EXT_USERNAME VARCHAR2 (4000)
  23. SPARE1 NUMBER
  24. SPARE2 NUMBER
  25. SPARE3 NUMBER
  26. SPARE4 VARCHAR2 (1000)
  27. SPARE5 VARCHAR2 (1000)
  28. SPARE6DATE
  29. SQL>Select User#,Name From User$Where Name='Scott';-- Find the user to change
  30. USER#NAME
  31. ----------------------------------------
  32. 84 SCOTT
  33. SQL>Select Count(*)FromScott. emp;
  34. COUNT(*)
  35. ----------
  36. 14
  37. SQL>Update User$Set Name='Scott2' Where User# = 84;-- Change User Name
  38. 1 row updated.
  39. SQL>Commit;-- Submit www.bkjia.com
  40. CommitComplete.
  41. SQL>Select Count(*)FromScott. emp;
  42. COUNT(*)
  43. ----------
  44. 14
  45. SQL>AlterSystemCheckpoint;
  46. System altered.
  47. SQL>Select Count(*)FromScott. emp;
  48. COUNT(*)
  49. ----------
  50. 14
  51. SQL>AlterSystem flush shared_pool;-- Refresh shared_pool
  52. System altered.
  53. SQL>Select Count(*)FromScott. emp;
  54. Select Count(*)FromScott. emp
  55. *
  56. ERRORAtLine 1:
  57. ORA-00942:Table Or ViewDoesNotExist
  58. SQL>Select Count(*)FromScott2.emp;-- Changed successfully
  59. COUNT(*)
  60. ----------
  61. 14

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.