暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

在Oracle中,TWO_TASK环境变量的作用是什么?

DB宝 2017-06-03
933



Q
题目如下所示:

在Oracle中,TWO_TASK环境变量的作用是什么?


     

A
答案如下所示:


Linux环境下,可以设置TWO_TASK环境变量,当用户连接数据库且没有指定服务名时,会自动利用TWO_TASK的设置作为环境变量连接数据库。其中,TWO_TASK的值为tnsnames.ora文件中配置的值。示例如下所示:

[LHRDB1:oracle]:/oracle>ORACLE_SID=
[LHRDB1:oracle]:/oracle>TWO_TASK=
[LHRDB1:oracle]:/oracle>sqlplus lhr/lhr
SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 31 16:17:38 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
[LHRDB1:oracle]:/oracle>more $ORACLE_HOME/net*/ad*/tns*
# tnsnames.ora Network Configuration File: oracle/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
lhrdb =
 (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.130)(PORT = 1521))
   (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SERVICE_NAME = lhrdb)
   )
 )
[LHRDB1:oracle]:/oracle>export TWO_TASK=lhrdb
[LHRDB1:oracle]:/oracle>sqlplus lhr/lhr
SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 31 16:17:53 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
LHR@lhrdb>
[LHRDB1:oracle]:/oracle>sqlplus as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 31 16:18:07 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
ERROR:
ORA-01017: invalid username/password; logon denied
Enter user-name:

需要注意的是,当配置了TWO_TASK环境变量后,就无法使用操作系统验证来登录数据库了,会报ORA-01031: insufficient privileges的错误。

类似地,在Windows环境下的变量是LOCAL,其设置方法和Linux下的TWO_TASK一致,如下所示:

C:\Users\boc>sqlplus lhr/lhr
SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 31 16:28:25 2016
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
ERROR:
ORA-12560: TNS:protocol adapter error
Enter user-name:
C:\Users\boc>more "%ORACLE_HOME%/network/admin/tnsnames.ora"
# tnsnames.ora Network Configuration File: D:\app\oracle\product\11.2.0.1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
lhrdb =
 (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = 22.188.194.64)(PORT = 1521))
   (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SERVICE_NAME = lhrdb)
   )
 )
C:\Users\boc>set LOCAL=lhrdb
C:\Users\boc>sqlplus lhr/lhr
SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 31 16:29:25 2016
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL>

& 说明:

有关TWO_TASKLOCAL的更多内容可以参考我的BLOGhttp://blog.itpub.net/26736162/viewspace-2112274/http://blog.itpub.net/26736162/viewspace-2112277/http://blog.itpub.net/26736162/viewspace-2123414/



DB笔试面试历史连接

http://mp.weixin.qq.com/s/Vm5PqNcDcITkOr9cQg6T7w

About Me:小麦苗

 本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用

● 作者博客地址:http://blog.itpub.net/26736162/abstract/1/

 本系列题目来源于作者的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

 版权所有,欢迎分享本文,转载请保留出处

 QQ:646634621  QQ群:230161599

● 题目解答若有不当之处,还望各位朋友批评指正,共同进步

长按下图识别二维码或微信扫描下图二维码来关注小麦苗的微信公众号:xiaomaimiaolhr,学习最实用的数据库技术。



最后修改时间:2020-01-10 21:12:21
文章转载自DB宝,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论