Oracle 12c 用户的创建
Oracle 12c 的账户可以分为公用账户和本地用户,共有账户是在CDB下创建,可以给所有的PDB用户使用,本地账户是只能在PDB中创建的账号
创建公共用户
alter session set container=CDB$ROOT;
create USER C##u02 identified by oracle container=all;
创建本地用户
alter session set container=pdb4;
create USER u01 identified by oracle container=current;
SQL> SELECT USERNAME,CON_ID,USER_ID FROM CDB_USERS WHERE USERNAME='U01';
USERNAME CON_ID USER_ID
------------------------------ ---------- ----------
U01 4 105
在CDB中创建测试账号
1 在CDB中创建账号必须以C##开头
alter session set container=CDB$ROOT;
SQL> create user orcl identified by a;
create user orcl identified by a
*
ERROR at line 1:
ORA-65096: invalid common user or role name
SQL> create user p##orcl identified by a;
create user p##orcl identified by a
*
ERROR at line 1:
ORA-65096: invalid common user or role name
SQL> create user c##a identified by a;
User created.
SQL> select username from dba_users where username like 'C##%';
USERNAME
--------------------------------------------------------------------------------
C##A
---说明本地用户不能以C##开头
alter session set container=pdb4;
SQL> create user c##B identified by B;
create user c##B identified by B
*
ERROR at line 1:
ORA-65094: invalid local user or role name
SQL> SELECT USERNAME,CON_ID,USER_ID FROM CDB_USERS WHERE USERNAME like 'C##%' ORDER BY USERNAME;
USERNAME CON_ID USER_ID
------------------------------ ---------- ----------
C##BOSWLL 4 103
C##BOSWLL 3 110
C##BOSWLL 1 102
C##BOSWLL 5 103
C##U02 4 106
C##U02 5 104
C##U02 1 103
C##U02 3 111
---创建公共用户时,不能在pdb中创建,必须在cdb中创建公共用户
SQL> alter session set container=pdb4;
Session altered.
SQL> create USER C##u02 identified by oracle container=all;
create USER C##u02 identified by oracle container=all
*
ERROR at line 1:
ORA-65050: Common DDLs only allowed in CDB$ROOT
总结:
1 公共用户必须以 C##开头,本地用户只能以字母开头,不能以C##用户开头
2 创建公共用户时,必须是在CDB$ROOT
3 如果在PDB中已经存在一个用户或者角色,则在CDB中不能创建相同的账号或者角色名