【SQL 笔记】Oracle 12c 如何调用 SCOTT 用户

Oracle 可真是太麻烦了

找到E:\app\oracle\product\12.1.0\dbhome_1\NETWORK\ADMIN文件夹,这的路径按自己的来走

备份三个 ora 文件:listener.ora、sqlnet.ora、tnsnames.ora(建个 bak 文件夹或者直接后面加 .bak 后缀都行)

然后修改 tnsnames.ora 文件为如下,可以看到多加了一块 PDBORCL 的区域,不然之后连接用户会出现ORA-12154: TNS: 无法解析指定的连接标识符错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# tnsnames.ora Network Configuration File: E:\app\oracle\product\12.1.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))


ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

PDBORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdborcl)
)
)

之后修改登录的容器为 PDBORCL,进入 sql 终端的命令如下:

1
sqlplus /nolog

然后在 sql 终端中依次输入以下命令:

1
2
3
4
5
6
conn sys/sys as sysdba
alter session set container=pdborcl;
startup
conn sys@pdborcl/sys as sysdba;
grant resource,dba to scott;
conn scott@pdborcl/tiger

连接上以后,输入以下命令查看是否正确更改:

1
show user

出现 USER 为 “SCOTT”

1
show parameter db_name

出现列表而不是ORA-00942: 表或视图不存在即可

文章目录
|