Cannot drop a database link after changing the global_name ORA-02024 [ID 382994.1]

Cannot drop a database link after changing the global_name ORA-02024 [ID 382994.1]

Modified 22-NOV-2010Type PROBLEMStatus MODERATED

In this Document
Symptoms
Cause
Solution

Platforms: 1-914CU;

This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process and therefore has not been subject to an independent technical review.

Applies to:

Oracle Server - Enterprise Edition - Version: 9.2.0.6 and later[Release: 9.2 and later ]
Information in this document applies to any platform.
***Checked for relevance on 14-Jan-2010***

Symptoms

Not able to drop a database link after changing the global_name of the database

Earlier global_name had did not have domain name attached to it. The newly added
global_name has a domain name attached to it

When trying to drop the database link after this change throws the following error

ORA-02024: database link not found

But database link is present and the query on user_db_links displays the value

Example :-

SQL> select * from global_name;

GLOBAL_NAME
---------------------------------------------------------
DB10GR2

SQL> create database link l1 connect to scott identified by tiger;

Database link created.

SQL> select db_link from user_db_links;

DB_LINK
---------------------------------------------------------
L1

SQL> alter database rename global_name to DB10GR2.WORLD;

Database altered.

SQL> select * from global_name;

GLOBAL_NAME
---------------------------------------------------------
DB10GR2.WORLD

SQL> drop database link l1;
drop database link l1
*
ERROR at line 1:
ORA-02024: database link not found

Even if the global_name is changed back to the original value, the same errors
occurs.

Cause

Initially when a database is created without domain in the global name, null will
used from domain as opposed to .world in earlier releases

Later on when the global_name is altered to contain the domain part also, this
domain remains even when the global_name is altered back a name without domain name

Example :-

SQL> select * from global_name;

GLOBAL_NAME
---------------------------------------------------------
DB10GR2

SQL> alter database rename global_name to DB10GR2.WORLD;

Database altered.

SQL> select * from global_name;

GLOBAL_NAME
---------------------------------------------------------
DB10GR2.WORLD

SQL> alter database rename global_name to DB10GR2;

Database altered.

SQL> select * from global_name;

GLOBAL_NAME
---------------------------------------------------------
DB10GR2.WORLD

The only option left to correct this is to update the base table props$

Solution

To implement the solution, please execute the following steps:

1)Take a complete consistent backup of the database

2)Execute the following:

$sqlplus /nolog
connect / as sysdba

SQL> update props$ set value$ = '<globalname without domain>' where name ='GLOBAL_DB_NAME';

SQL>commit;

3)

a) Then connect as the schema user that owns the DBLINK and try to drop it.

If you still get ORA-2024: database link not found , that means the domain name is in your cache and needs to be cleared.

b) Flush shared pool thrice and retry drop database link.
alter system flush SHARED_POOL;
alter system flush SHARED_POOL;
alter system flush SHARED_POOL;

c) If step b doesn't help, you need to bounce your database and try to drop the database link.

4)Once the database link is dropped, the global_name can be changed back to the
desired name containing domain part using the alter database rename global_name
statement

------------------------------------------------------------------------------

Blog http://blog.youkuaiyun.com/tianlesoftware

网上资源: http://tianlesoftware.download.youkuaiyun.com

相关视频:http://blog.youkuaiyun.com/tianlesoftware/archive/2009/11/27/4886500.aspx

DBA1 群:62697716(); DBA2 群:62697977()

DBA3 群:62697850 DBA 超级群:63306533;

聊天 群:40132017

--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请

ORA-02437错误表示在尝试验证主键约束时,发现表中存在违反主键唯一性的记录。对于错误信息 “cannot validate (JKS_FDS.PK_SXZJ_PERFORMANCE_ROLE) - primary key violated”,可以通过以下几种方法解决: ### 查找重复记录 可以使用SQL语句查找违反主键约束的重复记录。假设主键涉及的字段为 `id`,表名为 `SXZJ_PERFORMANCE_ROLE`,可以使用以下SQL语句: ```sql SELECT id, COUNT(*) FROM JKS_FDS.SXZJ_PERFORMANCE_ROLE GROUP BY id HAVING COUNT(*) > 1; ``` ### 删除重复记录 在找到重复记录后,可以选择删除多余的记录,只保留一条。可以使用以下方法: ```sql -- 先创建一个临时表,存储要保留的记录 CREATE TABLE temp_table AS SELECT MIN(rowid) as row_id FROM JKS_FDS.SXZJ_PERFORMANCE_ROLE GROUP BY id HAVING COUNT(*) > 1; -- 根据临时表中的rowid删除多余的重复记录 DELETE FROM JKS_FDS.SXZJ_PERFORMANCE_ROLE WHERE rowid NOT IN (SELECT row_id FROM temp_table); -- 删除临时表 DROP TABLE temp_table; ``` ### 禁用并重新启用约束 如果重复记录难以处理或者存在其他特殊情况,可以先禁用主键约束,处理完数据后再重新启用。 ```sql -- 禁用主键约束 ALTER TABLE JKS_FDS.SXZJ_PERFORMANCE_ROLE DISABLE CONSTRAINT PK_SXZJ_PERFORMANCE_ROLE; -- 处理数据,例如删除重复记录等 -- ... -- 重新启用主键约束 ALTER TABLE JKS_FDS.SXZJ_PERFORMANCE_ROLE ENABLE CONSTRAINT PK_SXZJ_PERFORMANCE_ROLE; ``` ### 检查数据插入逻辑 确保在应用程序中插入数据时,不会产生重复的主键值。检查数据插入的代码逻辑,添加必要的唯一性检查。例如,在Java中使用JDBC插入数据时,可以先查询数据库中是否已经存在该主键值: ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class InsertDataExample { public static void main(String[] args) { String url = "jdbc:oracle:thin:@localhost:1521:xe"; String username = "your_username"; String password = "your_password"; String idToInsert = "123"; try (Connection connection = DriverManager.getConnection(url, username, password)) { // 检查主键是否已存在 String checkQuery = "SELECT COUNT(*) FROM JKS_FDS.SXZJ_PERFORMANCE_ROLE WHERE id = ?"; try (PreparedStatement checkStatement = connection.prepareStatement(checkQuery)) { checkStatement.setString(1, idToInsert); ResultSet resultSet = checkStatement.executeQuery(); if (resultSet.next() && resultSet.getInt(1) == 0) { // 主键不存在,插入数据 String insertQuery = "INSERT INTO JKS_FDS.SXZJ_PERFORMANCE_ROLE (id, ...) VALUES (?, ...)"; try (PreparedStatement insertStatement = connection.prepareStatement(insertQuery)) { insertStatement.setString(1, idToInsert); // 设置其他参数 insertStatement.executeUpdate(); } } } } catch (SQLException e) { e.printStackTrace(); } } } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值