Create a New User in Oracle 12c
Oracle 12c introduces the CDB/PDB multitenant architecture. Creating regular users directly inside the Container Database (CDB) will throw errors. Common users created within the CDB must use the prefix c## / C##.
Log In
- Open Windows cmd and launch sqlplus
sqlplus
- Log into the database using the super‑administrator account
Enter user-name: sys as sysdba
Enter password: 【Enter your sys password set during installation】Code language: JavaScript (javascript)
Login success prompt:Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Create User
Incorrect Syntax
Goal: create user cat with password 123456
Execute SQL:
CREATE USER cat IDENTIFIED BY 123456;
ORA-65096: invalid common user or role nameCode language: HTTP (http)
Cause of error: You are currently in the CDB root container. Common users are forced to have the c## prefix. The name cat does not follow the naming rules.
Correct Way to Create Common User
Execute SQL:
CREATE USER c##cat IDENTIFIED BY Bm123321;Code language: CSS (css)
Execution result:User created.
Assign User Privileges
Wrong Grant Statement
GRANT CONNECT, RESOURCE, DBA TO cat;
ORA-01917: user or role 'CAT' does not existCode language: JavaScript (javascript)
The username is c##cat. When granting permissions, you must use the exact same username used at creation. Do not shorten it to cat.
Correct Grant Statement
GRANT CONNECT, RESOURCE, DBA TO c##cat;Code language: CSS (css)
Privilege description:
CONNECT: basic login and connection permissionRESOURCE: common developer role, allows creating tables, indexes and other objectsDBA: full database administrator privileges (use in test environments; avoid assigning freely in production)
Verify Login with New User
- Run
exitto close the sys admin session, then reopen sqlplus
SQL> exitCode language: PHP (php)
- Attempt incorrect login
Enter user-name: cat
Enter password: 123456
Error:ORA-01017: invalid username/password; logon denied
- Correct login method
Enter user-name: c##cat
Enter password: 123456Code language: CSS (css)
Successfully connected to database.
Create user