PLSQL連接本地oracle或遠程oracle數據庫實現隨意切換功能

 更新時間:2021年09月08日 16:43:48   作者:前方一片光明  
這篇文章主要介紹了PLSQL連接本地oracle或遠程oracle數據庫實現隨意切換功能,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

前言

先贊后看,此生必賺!

每次安裝Oracle以后,都會出現使用plsql連接不上的問題!多次重啟電腦、重裝系統的磨人經歷之后,

今天看到這篇文章算是你我之幸!希望能幫助廣大技術人員減少一些時間,順利進行連接!

注:也可以用plsql連接遠程數據庫(只要有oracle的network\admin\tnsnames.ora就行)。

首先下載64位oracle以及32位輕量級客戶端(注意版本的對應,我用的是11g的oracle和11.2的客戶端):

點擊進入oracle下載頁面 點擊進入客戶端下載頁面

以下步驟請自行更改路徑,不然,出錯了別怪我哦:

step1 復制network文件

oracle安裝到某路徑下,安裝步驟很簡單,網上可以搜到!

客戶端隨便解壓到一個路徑,我的是放在D:\app\shuhao\instantclient_11_2了。

然后把oracle中的D:\app\shuhao\product\11.2.0\dbhome_1里面的整個network文件夾復制,

粘貼到客戶端文件夾D:\app\shuhao\instantclient_11_2下面,如下圖所示:

step2 修改配置文件

2.1 修改oracle數據庫文件

D:\app\shuhao\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora文件內容,添加一個SID_DESC:

# listener.ora Network Configuration File: D:\app\shuhao\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.
 
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = D:\app\shuhao\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:D:\app\shuhao\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )
#下面的SID_DESC是新增加的內容,注意修改ORACLE_HOME路徑
    (SID_DESC =
      (SID_NAME = orcl)
      (ORACLE_HOME = D:\app\shuhao\product\11.2.0\dbhome_1)
      (GLOBAL_DBNAME = orcl)
    )
  )
 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
  )
 
ADR_BASE_LISTENER = D:\app\shuhao

2.2 修改oracle數據庫文件

D:\app\shuhao\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora文件內容,源文件沒有做改動:

# tnsnames.ora Network Configuration File: D:\app\shuhao\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
 
ORACLR_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )
 
LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
 
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

2.3 修改客戶端文件

D:\app\shuhao\instantclient_11_2\network\admin\tnsnames.ora文件內容:

# tnsnames.ora Network Configuration File: D:\app\shuhao\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
 
ORACLR_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )
 
LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
 
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
#新增 @ 標識符,用于區分本地與遠程oracle
ORCL@192.168.0.164 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.164)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

step3 配置OCI

不登錄plsql,直接按Cancel,進入后在Tools--->Preferences---->Connection中配置OCI為32位客戶端的OCI

D:\app\shuhao\instantclient_11_2\oci.dll

step4 環境變量配置

添加前2個系統變量:

1. 變量名:TNS_ADMIN

變量值:D:\app\shuhao\instantclient_11_2\network\admin

2. 變量名:NLS_LANG

變量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK

3. Path中配置加入:

D:\app\shuhao\product\11.2.0\dbhome_1\BIN;D:\app\shuhao\instantclient_11_2;

step5 重啟電腦(有時候不需要重啟)

啟動oracle服務與監聽,這個就不需要描述了。

step6 登錄plsql!!!

當看到Database下拉框中有本地的ORCL以及遠程的ORCL@192.168.0.164就算成功了!!!

OK, GAME OVER !

到此這篇關于PLSQL連接本地oracle或遠程oracle數據庫實現隨意切換功能的文章就介紹到這了,更多相關PLSQL連接本地遠程oracle內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

精品国内自产拍在线观看