$sqlplus system/oracle@XEPDB1
SQL*Plus: Release 18.0.0.0.0 Production on Wed Oct 9 13:59:04 2019
Version 18.1.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Last Successful login time: Wed Oct 09 2019 13:56:31 +02:00
Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
system@XEPDB1> create user a identified by a;
User created.
Elapsed: 00:00:00.43
system@XEPDB1> create user b identified by b;
User created.
Elapsed: 00:00:00.14
system@XEPDB1> grant create session to a;
Grant succeeded.
Elapsed: 00:00:00.05
system@XEPDB1> grant create session to b;
Grant succeeded.
Elapsed: 00:00:00.01
system@XEPDB1> exit
在 Linux 上,像这样设置TWO_TASK环境变量:
$export TWO_TASK=XEPDB1
$sqlplus system/oracle
SQL*Plus: Release 18.0.0.0.0 Production on Wed Oct 9 14:07:25 2019
Version 18.1.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Last Successful login time: Wed Oct 09 2019 13:59:04 +02:00
Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
system@XEPDB1> connect a/a
Connected.
a@XEPDB1> connect b/b
Connected.
b@XEPDB1> exit
Disconnected from Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
当然,也将其作为参数传递。
然后您可以在脚本中使用以下内容:
您可以在启动 sqlplus之前定义环境 (TNS_ALIAS) 。
首先让我们创建两个用户(a 和 b)
在 Linux 上,像这样设置TWO_TASK环境变量:
您将从 sqlplus 提示符中看到您登录的用户。
作为旁注,当您意识到您的 TNS_ALIAS 指向 PROD 数据库而不是 TEST 数据库时,在 sql 脚本中定义与 TNS_ALIAS 的连接会在某一时刻使您难以忍受。
Windows 上的TWO_TASK等价物是LOCAL ala
PS>$env:LOCAL = "XEPDB1"