这三个参数都时操作系统中的环境变量。
在UNIX中,三个参数都存在,优先级如下:
1. TWO_TASK
2. LOCAL
3. ORACLE_SID
TWO_TASK是unix一个隐含的变量,该变量的值始终是指向连接到当前实例的连接字符串值。sqlplus在不指定连接字符串,而默认使用的连接字符串名。LOCAL在unix平台下基本上没什么用,可以忽略。
在默认的情况下,TWO_TASK是不需要设置的,是一个隐含的变量。我们可以进行测试,测试数据库ORACLE_SID=test,连接字符串=testxx
在不作任何设置的时候,我们
sqlplus xigua/xigua 能连接到数据库。
export TWO_TASK=test
sqlplus xigua/xigua 提示无法解析服务名。
export TWO_TASK=testxx
sqlplus xigua/xigua 又能连接到数据库。[@more@]当然,在上面的任何一种情况下,如果后面带上了连接字符串,那肯定是可以连接上的。
上面的所有测试都是单实例的情况下,多实例的情况有些不同,必须要设置ORACLE_SID参数。
在windows系统中,则不存在TWO_TASK环境变量,起作用的就是LOCAL变量了。LOCAL变量的作用同TWO_TASK变量。
另外,我们还可以发现,在不显式的指定TWO_TASK的值情况下,我们关闭监听,也可以利用操作系统验证登陆sqlplus '/as sysdba'。 如果显式的指定TWO_TASK的值,将被强制使用本地服务验证,必须使用监听服务。
[oracle@VM:oracle] lsnrctl stop
[oracle@VM:oracle] sqlplus ' /as sysdba '
SQL*Plus: Release 9.2.0.4.0 - Production on Sat Jul 7 13:19:50 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
SQL> quit
[oracle@VM:oracle] export TWO_TASK=test #将TWO_TASK设置成非连接字符串值
[oracle@VM:oracle] sqlplus ' /as sysdba '
SQL*Plus: Release 9.2.0.4.0 - Production on Sat Jul 7 13:20:07 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve service name
Enter user-name:
[oracle@VM:oracle] export TWO_TASK=testxx -将TWO_TASK设置成连接字符串值
[oracle@VM:oracle] sqlplus ' /as sysdba '
SQL*Plus: Release 9.2.0.4.0 - Production on Sat Jul 7 13:20:15 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
ERROR:
ORA-12541: TNS:no listener
Enter user-name: