创建用户,并为用户分配适当的概要文件和角色。可采取调用企业管理器数据库Express,以DBA1用户和SYSDBA登录后进行创建。但需要处理批量创建任务时,此方法并非高效。
另一种办法可以通过Oracle自带的gedit Text Editor创建一个sql脚本,具体指令为:
create user "&&username" identified by newuser profile "HRPROFILE" password expire account unlock default tablespace "USERS" temporary tablespace "TEMP";
grant “&&role” to “&&username”;
grant "CONNECT" to “&&username”;
保存名称为P6script.sql文件,保存位置为/home/oracle/P6script.sql
运行P6script.sql文件,使用下面代码:
sqlplus dba1/oracle_4U as sysdba @/home/oracle/P6script.sql
根据提示输入需要创建的用户名(JGOODMAN)和角色(HRMANAGER):
[oracle@12c-env Desktop]$ sqlplus dba1/oracle_4U as sysdba @/home/oracle/P6script.sql
SQL*Plus: Release 12.1.0.2.0 Production on Sat Aug 13 15:52:33 2022
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Enter value for username: JGOODMAN
old 1: create user "&&username" identified by newuser profile "HRPROFILE" password expire account unlock default tablespace "USERS" temporary tablespace "TEMP"
new 1: create user "JGOODMAN" identified by newuser profile "HRPROFILE" password expire account unlock default tablespace "USERS" temporary tablespace "TEMP"
User created.
Enter value for role: HRMANAGER
old 1: grant "&&role" to "&&username"
new 1: grant "HRMANAGER" to "JGOODMAN"
Grant succeeded.
old 1: grant "CONNECT" to "&&username"
new 1: grant "CONNECT" to "JGOODMAN"
Grant succeeded.
SQL> connect jgoodman
Enter password:
ERROR:
ORA-28001: the password has expired
Changing password for jgoodman
New password:
Retype new password:
Password changed
Connected.
备注:创建好用户后,首次登陆时需更改口令,默认口令为newuser