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 [email protected] = (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以及遠程的[email protected]就算成功瞭!!!
OK, GAME OVER !
到此這篇關於PLSQL連接本地oracle或遠程oracle數據庫實現隨意切換功能的文章就介紹到這瞭,更多相關PLSQL連接本地遠程oracle內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!
推薦閱讀:
- IntelliJ DataGrip Oracle 11g遠程連接的方法步驟
- PLSQL Developer13.0.4註冊和使用教程詳解
- 教你使用PLSQLDeveloper14連接Oracle11g的詳細過程
- 處理Oracle監聽程序當前無法識別連接描述符中請求的服務異常(ORA-12514)
- C#連接ORACLE出現亂碼問題的解決方法