Oracle 11.2にtnsnames.oraの使い方

1.tnsnames.ora
説明:tnsnames.oraは接続先DBを指定するための記述をするファイルです。
クライアント側に配置します。

場所 C:\app\client\username\product\11.2.0\client_1\network\admin
構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[接続先DBのサービス名] =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = [接続先サーバのホスト名またはIPアドレス])(PORT = [接続先サーバのポート番号]))
)
(CONNECT_DATA =
(SERVICE_NAME = [接続先DBのサービス名])
)
)
[接続先DBのサービス名] = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = [接続先サーバのホスト名またはIPアドレス])(PORT = [接続先サーバのポート番号])) ) (CONNECT_DATA = (SERVICE_NAME = [接続先DBのサービス名]) ) )
[接続先DBのサービス名] =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = [接続先サーバのホスト名またはIPアドレス])(PORT = [接続先サーバのポート番号]))

)

(CONNECT_DATA =

(SERVICE_NAME = [接続先DBのサービス名])

)

)

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
CFT =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.102.3)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = CFT)
)
)
CFT = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.102.3)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = CFT) ) )
CFT =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.102.3)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = CFT)
    )
  )

2.システム環境変数
Path: C:\app\client\username\product\11.2.0\client_1\bin\

3.コマンドプロンプトでsqlplusでOracleに接続

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
C:\WINDOWS\system32>sqlplus username/pwd@cft
SQL*Plus: Release 11.2.0.1.0 Production on 水 1027 18:44:30 2021
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
に接続されました。
SQL>
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
C:\WINDOWS\system32>sqlplus username/pwd@cft SQL*Plus: Release 11.2.0.1.0 Production on 水 10月 27 18:44:30 2021 Copyright (c) 1982, 2016, Oracle. All rights reserved. Oracle Database 11g Release 11.2.0.1.0 - 64bit Production に接続されました。 SQL> SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production
C:\WINDOWS\system32>sqlplus username/pwd@cft

SQL*Plus: Release 11.2.0.1.0 Production on 水 10月 27 18:44:30 2021

Copyright (c) 1982, 2016, Oracle.  All rights reserved.



Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
に接続されました。
SQL>
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

 

Oracle

Posted by arkgame