PLSQL连接本地oracle或远程oracle数据库实现随意切换功能

时间:2022-06-16 02:48:48

前言

先赞后看,此生必赚!

每次安装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下面,如下图所示:

PLSQL连接本地oracle或远程oracle数据库实现随意切换功能

step2 修改配置文件

 

2.1 修改oracle数据库文件

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

  1. # listener.ora Network Configuration File: D:\app\shuhao\product\11.2.0\dbhome_1\network\admin\listener.ora
  2. # Generated by Oracle configuration tools.
  3.  
  4. SID_LIST_LISTENER =
  5. (SID_LIST =
  6. (SID_DESC =
  7. (SID_NAME = CLRExtProc)
  8. (ORACLE_HOME = D:\app\shuhao\product\11.2.0\dbhome_1)
  9. (PROGRAM = extproc)
  10. (ENVS = "EXTPROC_DLLS=ONLY:D:\app\shuhao\product\11.2.0\dbhome_1\bin\oraclr11.dll")
  11. )
  12. #下面的SID_DESC是新增加的内容,注意修改ORACLE_HOME路径
  13. (SID_DESC =
  14. (SID_NAME = orcl)
  15. (ORACLE_HOME = D:\app\shuhao\product\11.2.0\dbhome_1)
  16. (GLOBAL_DBNAME = orcl)
  17. )
  18. )
  19.  
  20. LISTENER =
  21. (DESCRIPTION_LIST =
  22. (DESCRIPTION =
  23. (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  24. )
  25. )
  26.  
  27. ADR_BASE_LISTENER = D:\app\shuhao

2.2 修改oracle数据库文件

D:\app\shuhao\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora文件内容,源文件没有做改动:

  1. # tnsnames.ora Network Configuration File: D:\app\shuhao\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
  2. # Generated by Oracle configuration tools.
  3.  
  4. ORACLR_CONNECTION_DATA =
  5. (DESCRIPTION =
  6. (ADDRESS_LIST =
  7. (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  8. )
  9. (CONNECT_DATA =
  10. (SERVICE_NAME = orcl)
  11. )
  12. )
  13.  
  14. LISTENER_ORCL =
  15. (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  16.  
  17. ORCL =
  18. (DESCRIPTION =
  19. (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  20. (CONNECT_DATA =
  21. (SERVER = DEDICATED)
  22. (SERVICE_NAME = orcl)
  23. )
  24. )

2.3 修改客户端文件

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

  1. # tnsnames.ora Network Configuration File: D:\app\shuhao\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
  2. # Generated by Oracle configuration tools.
  3.  
  4. ORACLR_CONNECTION_DATA =
  5. (DESCRIPTION =
  6. (ADDRESS_LIST =
  7. (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  8. )
  9. (CONNECT_DATA =
  10. (SERVICE_NAME = orcl)
  11. )
  12. )
  13.  
  14. LISTENER_ORCL =
  15. (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  16.  
  17. ORCL =
  18. (DESCRIPTION =
  19. (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  20. (CONNECT_DATA =
  21. (SERVER = DEDICATED)
  22. (SERVICE_NAME = orcl)
  23. )
  24. )
  25. #新增 @ 标识符,用于区分本地与远程oracle
  26. ORCL@192.168.0.164 =
  27. (DESCRIPTION =
  28. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.164)(PORT = 1521))
  29. (CONNECT_DATA =
  30. (SERVER = DEDICATED)
  31. (SERVICE_NAME = orcl)
  32. )
  33. )

step3 配置OCI

不登录plsql,直接按Cancel,进入后在Tools--->Preferences---->Connection中配置OCI为32位客户端的OCI

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

PLSQL连接本地oracle或远程oracle数据库实现随意切换功能

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就算成功了!!!

PLSQL连接本地oracle或远程oracle数据库实现随意切换功能

OK, GAME OVER !

到此这篇关于PLSQL连接本地oracle或远程oracle数据库实现随意切换功能的文章就介绍到这了,更多相关PLSQL连接本地远程oracle内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/qq_26230421/article/details/79047527