Oracle“ ORA-12162:TNS:net服务名称指定不正确”错误和解决方案

During the connection to the Oracle Database server with the sqlplus we may get an error with the ORA-12162 specifier. This error will prevent to connect to the Oracle Database Server.

在使用sqlplus连接到Oracle数据库服务器的过程中,ORA-12162说明符可能会出错。 此错误将阻止连接到Oracle数据库服务器。

“ ORA-12162:TNS:net服务名称指定不正确”错误 (“ORA-12162: TNS:net service name is incorrectly specified” Error)

This error will be look like below. This error is caused by not setting $ORACLE_HOME and $ORACLE_SID environment variables for Linux and Windows Operating systems.

该错误如下所示。 此错误是由于未为Linux和Windows操作系统设置$ ORACLE_HOME和$ ORACLE_SID环境变量引起的。

"ORA-12162: TNS:net service name is incorrectly specified" Error
“ORA-12162: TNS:net service name is incorrectly specified” Error
“ ORA-12162:TNS:net服务名称指定不正确”错误

检查$ ORACLE_HOME环境变量(Check $ORACLE_HOME Environment Variable)

$ORACLE_HOME is important operating system variable used by Oracle Database. First we will check whether it is set or set properly with the echo command like below in Linux.

$ORACLE_HOME是Oracle数据库使用的重要操作系统变量。 首先,我们将使用echo命令(如Linux中的以下命令)检查它是否已设置或正确设置。

$ echo $ORACLE_HOME
Check $ORACLE_HOME Environment Variable
Check $ORACLE_HOME Environment Variable
检查$ ORACLE_HOME环境变量

For windows we can list environment variables with env command.

对于Windows,我们可以使用env命令列出环境变量。

> env

在Windows和Linux中设置$ ORACLE_HOME环境变量 (Set $ORACLE_HOME  Environment Variable in Windows and Linux)

We will set $ORACLE_HOME environment variable. This will be used by related tools. We can set environment variable for Linux with export command like below.

我们将设置$ORACLE_HOME环境变量。 相关工具将使用它。 我们可以使用如下导出命令为Linux设置环境变量。

$ export ORACLE_HOME="/home/oracle"

We can make this environment variable persistent between boots by adding this line to the .bashrc file of the user.

通过将此行添加到用户的.bashrc文件中,我们可以使此环境变量在两次引导之间保持不变。

We can use following tutorial to add ORACLE_HOME environment variable by using following tutorial in Windows operating system.

通过在Windows操作系统中使用以下教程,我们可以使用以下教程来添加ORACLE_HOME环境变量。

How To List, Set, Get Windows Environment Variables With Set Command In Command Line MS-DOS?

如何在命令行MS-DOS中使用Set命令列出,设置和获取Windows环境变量?

检查$ ORACLE_SID环境变量 (Check $ORACLE_SID Environment Variable)

We will check $ORACLE_SID environment variable which also requires to solve error. We will use echo command again.

我们将检查$ORACLE_SID环境变量,该变量也需要解决错误。 我们将再次使用echo命令。

$ echo $ORACLE_SID

在Linux中设置$ ORACLE_SID环境变量 (Set $ORACLE_SID Environment Variable in Linux)

Now the final step is setting $ORACLE_SID in Linux environment. This will be used by sqlplus to use as Oracle SID while connecting. In this case we will set XE as SID.

现在,最后一步是在Linux环境中设置$ORACLE_SID 。 连接时, sqlplus将使用它作为Oracle SID。 在这种情况下,我们将XE设置为SID。

$ export ORACLE_SID="XE"

We can make this permanent by adding .bashrc of the user like below.

我们可以通过添加用户的.bashrc使其永久化,如下所示。

$ echo "export ORACLE_SID" >> ~/.bashrc
LEARN MORE  Oracle Database "sqlplus: error while loading shared libraries: libsqlplus.so" Error and Solution
了解更多信息Oracle Database“ sqlplus:加载共享库时出错:libsqlplus.so”错误和解决方案

翻译自: https://www.poftut.com/oracle-ora-12162-tnsnet-service-name-is-incorrectly-specified-error-and-solution/

### 解决 Oracle 错误 ORA-01113 ORA-01110 当遇到 `ORA-01113` `ORA-01110` 错误时,通常意味着数据文件需要介质恢复才能继续操作。以下是详细的解决方法: #### 关闭并重启数据库实例 为了确保数据库处于一致状态,在执行任何修复之前应先正常关闭再启动数据库实例。 ```sql shutdown immediate; startup; ``` 如果此时仍然收到 `ORA-01113` `ORA-01110` 错误提示,则表明指定的数据文件确实存在问题[^4]。 #### 执行介质恢复 针对受影响的数据文件进行特定的介质恢复工作是必要的步骤之一。通过以下命令可完成这一过程: ```sql recover datafile 'G:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\SYSTEM01.DBF'; ``` 此命令会尝试应用所有可用的日志记录直到达到一致性点为止[^5]。 #### 重新打开数据库 一旦成功完成了上述恢复流程之后,就可以再次尝试开启数据库了: ```sql alter database open; ``` 假如一切顺利的话,现在应该能够正常使用该数据库会再碰到之前的错误消息了。 另外值得注意的是,某些情况下可能还需要进一步的操作比如使用 `resetlogs` 参数来重置日志序列号以匹配新的SCN (System Change Number),这取决于具体的环境配置以及所使用的Oracle版本等因素影响[^3]。 对于频繁遭遇这类问题的情况,考虑部署专门的一键恢复工具可能会是一个错的选择,它能简化日常维护工作中涉及到的各种复杂场景下的快速响应机制[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值