如何调试 ORA-01775:同义词循环链?

发布于 2024-07-07 17:24:29 字数 148 浏览 11 评论 0原文

我熟悉 ORA-01775: 循环同义词链背后的问题,但是有什么技巧可以调试它,还是我只需要“创建或替换”我的方式来摆脱它?

有没有办法查询架构或其他方式来找出公共同义词的当前定义是什么?

更棒的是图形工具,但在这一点上,任何东西都会有帮助。

I'm familiar with the issue behind ORA-01775: looping chain of synonyms, but is there any trick to debugging it, or do I just have to "create or replace" my way out of it?

Is there a way to query the schema or whatever to find out what the current definition of a public synonym is?

Even more awesome would be a graphical tool, but at this point, anything would be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

治碍 2024-07-14 17:24:29

事实证明,问题实际上并不是同义词的循环链,而是同义词指向了一个不存在的视图。

在这种情况下,Oracle 显然会错误地作为循环链。

As it turns out, the problem wasn't actually a looping chain of synonyms, but the fact that the synonym was pointing to a view that did not exist.

Oracle apparently errors out as a looping chain in this condition.

失而复得 2024-07-14 17:24:29

如果您使用 TOAD,请转至 View>Toad Options>Oracle>General,然后从 EXPLAIN PLAN 部分中删除 TOAD_PLAN_TABLE 并放置 PLAN_TABLE

If you are using TOAD, go to View>Toad Options>Oracle>General and remove TOAD_PLAN_TABLE from EXPLAIN PLAN section and put PLAN_TABLE

九歌凝 2024-07-14 17:24:29

数据字典表DBA_SYNONYMS包含有关数据库中所有同义词的信息。 因此,您可以运行查询

SELECT table_owner, table_name, db_link
  FROM dba_synonyms 
 WHERE owner        = 'PUBLIC'
   AND synonym_name = <<synonym name>>

来查看公共同义词当前指向的内容。

The data dictionary table DBA_SYNONYMS has information about all the synonyms in a database. So you can run the query

SELECT table_owner, table_name, db_link
  FROM dba_synonyms 
 WHERE owner        = 'PUBLIC'
   AND synonym_name = <<synonym name>>

to see what the public synonym currently points at.

泪之魂 2024-07-14 17:24:29

此错误代码的不太直观的解决方案似乎是同义词所指向的对象存在问题。

这是我用于查找指向错误对象的同义词的 SQL。

SELECT S.OWNER as SYN_OWNER, S.SYNONYM_NAME as SYN_NAME,
    S.TABLE_OWNER as OBJ_OWNER, S.TABLE_NAME as OBJ_NAME,
    CASE WHEN O.OWNER is null THEN 'MISSING' ELSE O.STATUS END as OBJ_STATUS
FROM DBA_SYNONYMS S
    LEFT JOIN DBA_OBJECTS O ON S.TABLE_OWNER = O.OWNER AND S.TABLE_NAME = O.OBJECT_NAME
WHERE O.OWNER is null
    OR O.STATUS != 'VALID';

The less intuitive solution to this error code seems to be problems with the objects that the synonym is pointing to.

Here is my SQL for finding synonyms that point to erroneous objects.

SELECT S.OWNER as SYN_OWNER, S.SYNONYM_NAME as SYN_NAME,
    S.TABLE_OWNER as OBJ_OWNER, S.TABLE_NAME as OBJ_NAME,
    CASE WHEN O.OWNER is null THEN 'MISSING' ELSE O.STATUS END as OBJ_STATUS
FROM DBA_SYNONYMS S
    LEFT JOIN DBA_OBJECTS O ON S.TABLE_OWNER = O.OWNER AND S.TABLE_NAME = O.OBJECT_NAME
WHERE O.OWNER is null
    OR O.STATUS != 'VALID';
溺孤伤于心 2024-07-14 17:24:29

尝试此选择来查找有问题的同义词,它列出了指向不存在的对象的所有同义词(表、视图、序列、包、过程、函数)

SELECT *
FROM dba_synonyms
WHERE table_owner = 'USER'
    AND (
        NOT EXISTS (
            SELECT *
            FROM dba_tables
            WHERE dba_synonyms.table_name = dba_tables.TABLE_NAME
            )
        AND NOT EXISTS (
            SELECT *
            FROM dba_views
            WHERE dba_synonyms.table_name = dba_views.VIEW_NAME
            )
        AND NOT EXISTS (
            SELECT *
            FROM dba_sequences
            WHERE dba_synonyms.table_name = dba_sequences.sequence_NAME
            )
        AND NOT EXISTS (
            SELECT *
            FROM dba_dependencies
            WHERE type IN (
                    'PACKAGE'
                    ,'PROCEDURE'
                    ,'FUNCTION'
                    )
                AND dba_synonyms.table_name = dba_dependencies.NAME
            )
        )

Try this select to find the problematic synonyms, it lists all synonyms that are pointing to an object that does not exist (tables,views,sequences,packages, procedures, functions)

SELECT *
FROM dba_synonyms
WHERE table_owner = 'USER'
    AND (
        NOT EXISTS (
            SELECT *
            FROM dba_tables
            WHERE dba_synonyms.table_name = dba_tables.TABLE_NAME
            )
        AND NOT EXISTS (
            SELECT *
            FROM dba_views
            WHERE dba_synonyms.table_name = dba_views.VIEW_NAME
            )
        AND NOT EXISTS (
            SELECT *
            FROM dba_sequences
            WHERE dba_synonyms.table_name = dba_sequences.sequence_NAME
            )
        AND NOT EXISTS (
            SELECT *
            FROM dba_dependencies
            WHERE type IN (
                    'PACKAGE'
                    ,'PROCEDURE'
                    ,'FUNCTION'
                    )
                AND dba_synonyms.table_name = dba_dependencies.NAME
            )
        )
好多鱼好多余 2024-07-14 17:24:29

今天我得到了这个错误,经过调试后我发现实际的表丢失了,我是使用同义词来引用的。 所以我建议 - 首先检查表是否存在! :-))

Today I got this error, and after debugging I figured out that the actual tables were misssing, which I was referring using synonyms. So I suggest - first check that whether the tables exists!! :-))

丢了幸福的猪 2024-07-14 17:24:29

步骤 1) 查看该名称存在哪些对象:

select * from all_objects where object_name = upper('&object_name');

可能存在同义词但不存在表?


步骤 2) 如果这不是问题,请调查同义词:

select * from all_synonyms where synonym_name = upper('&synonym_name');

可能缺少该同义词的基础表或视图?

Step 1) See what Objects exist with the name:

select * from all_objects where object_name = upper('&object_name');

It could be that a Synonym exists but no Table?


Step 2) If that's not the problem, investigate the Synonym:

select * from all_synonyms where synonym_name = upper('&synonym_name');

It could be that an underlying Table or View to that Synonym is missing?

命硬 2024-07-14 17:24:29

开发人员意外编写了生成并运行以下 SQL 语句的代码 CREATE OR REPLACE PUBLIC SYNONYM "DUAL" FOR "DUAL";,这导致 select * from dba_synonyms where table_name = 'DUAL';
返回PUBLIC DUAL SOME_USER DUAL 而不是PUBLIC DUAL SYS DUAL

我们能够修复它(感谢如何重新创建公共同义词“DUAL”?) 通过运行

ALTER SYSTEM SET "_SYSTEM_TRIG_ENABLED"=FALSE SCOPE=MEMORY;
CREATE OR REPLACE PUBLIC SYNONYM DUAL FOR SYS.DUAL;
ALTER SYSTEM SET "_SYSTEM_TRIG_ENABLED"=true SCOPE=MEMORY;

A developer accidentally wrote code that generated and ran the following SQL statement CREATE OR REPLACE PUBLIC SYNONYM "DUAL" FOR "DUAL"; which caused select * from dba_synonyms where table_name = 'DUAL';
to return PUBLIC DUAL SOME_USER DUAL rather than PUBLIC DUAL SYS DUAL.

We were able to fix it (thanks to How to recreate public synonym "DUAL"?) by running

ALTER SYSTEM SET "_SYSTEM_TRIG_ENABLED"=FALSE SCOPE=MEMORY;
CREATE OR REPLACE PUBLIC SYNONYM DUAL FOR SYS.DUAL;
ALTER SYSTEM SET "_SYSTEM_TRIG_ENABLED"=true SCOPE=MEMORY;
草莓味的萝莉 2024-07-14 17:24:29

虽然 Jarrod 的答案是一个好主意,并且涵盖了更广泛的相关问题,但我发现在 Oracle 论坛中找到的这个查询可以更直接地解决(最初陈述的)问题:

select owner, synonym_name, connect_by_iscycle CYCLE
from dba_synonyms
where connect_by_iscycle > 0
connect by nocycle prior table_name = synonym_name
and prior table_owner = owner
union
select 'PUBLIC', synonym_name, 1
from dba_synonyms
where owner = 'PUBLIC'
and table_name = synonym_name
and (table_name, table_owner) not in (select object_name, owner from dba_objects
where object_type != 'SYNONYM')

https://community.oracle.com/message/4176300#4176300

您不必费力地浏览其他类型的无效对象。 只是那些实际上处于无限循环中的内容。

While Jarrod's answer is a good idea, and catches a broader range of related problems, I found this query found in Oracle forums to more directly address the (originally stated) issue:

select owner, synonym_name, connect_by_iscycle CYCLE
from dba_synonyms
where connect_by_iscycle > 0
connect by nocycle prior table_name = synonym_name
and prior table_owner = owner
union
select 'PUBLIC', synonym_name, 1
from dba_synonyms
where owner = 'PUBLIC'
and table_name = synonym_name
and (table_name, table_owner) not in (select object_name, owner from dba_objects
where object_type != 'SYNONYM')

https://community.oracle.com/message/4176300#4176300

You will not have to wade through other kinds of invalid objects. Just those that are actually in endless loops.

只想待在家 2024-07-14 17:24:29

我遇到了类似的问题,结果是由于表和模式名称中缺少双引号引起的。

I had a similar problem, which turned out to be caused by missing double quotes off the table and schema name.

久随 2024-07-14 17:24:29

我们遇到了相同的 ORA-01775 错误,但在我们的例子中,模式用户在几个公共同义词上缺少一些“授予选择”。

We had the same ORA-01775 error but in our case, the schema user was missing some 'grant select' on a couple of the public synonyms.

北斗星光 2024-07-14 17:24:29

我们今天遇到了这个错误。
这就是我们调试和修复它的方法。

  1. 由于此错误 ORA-01775,程序包进入无效状态。

  2. 根据错误行号,我们检查了package主体代码,找到了试图将数据插入的代码。

  3. 我们运行以下查询来检查上述同义词是否存在。

    SELECT * FROM DBA_TABLES WHERE TABLE_NAME = '&TABLE_NAME';   -- 没有返回行 
    
      SELECT * FROM DBA_SYNONYMS WHERE SYNONYM_NAME = '&SYNONYM_NAME';   -- 返回 1 行 
      
  4. 据此我们得出结论,需要重新创建该表。 由于同义词指向一个不存在的

  5. DBA 团队重新创建了该表,这解决了该问题。

We encountered this error today.
This is how we debugged and fixed it.

  1. Package went to invalid state due to this error ORA-01775.

  2. With the error line number , We went thru the package body code and found the code which was trying to insert data into a table.

  3. We ran below queries to check if the above table and synonym exists.

    SELECT * FROM DBA_TABLES WHERE TABLE_NAME = '&TABLE_NAME';  -- No rows returned
    
    SELECT * FROM DBA_SYNONYMS WHERE SYNONYM_NAME = '&SYNONYM_NAME'; -- 1 row returned
    
  4. With this we concluded that the table needs to be re- created. As the synonym was pointing to a table that did not exist.

  5. DBA team re-created the table and this fixed the issue.

鱼忆七猫命九 2024-07-14 17:24:29

ORA-01775: 同义词循环链
当我尝试编译一个包时,我遇到了上述错误,该包使用的对象已创建同义词,但底层对象不可用。

ORA-01775: looping chain of synonyms
I faced the above error while I was trying to compile a Package which was using an object for which synonym was created however underlying object was not available.

伴我老 2024-07-14 17:24:29

我使用以下 sql 来查找 all_synonyms 中没有与 object_name 对应的对象的条目(在 user_objects 中):

 select * 
   from all_synonyms 
   where table_owner = 'SCOTT' 
     and synonym_name not like '%/%'
     and table_name not in (
       select object_name from user_objects
         where object_type in (
           'TABLE', 'VIEW', 'PACKAGE', 'SEQUENCE',
           'PROCEDURE', 'FUNCTION', 'TYPE'
         )
    );

I'm using the following sql to find entries in all_synonyms where there is no corresponding object for the object_name (in user_objects):

 select * 
   from all_synonyms 
   where table_owner = 'SCOTT' 
     and synonym_name not like '%/%'
     and table_name not in (
       select object_name from user_objects
         where object_type in (
           'TABLE', 'VIEW', 'PACKAGE', 'SEQUENCE',
           'PROCEDURE', 'FUNCTION', 'TYPE'
         )
    );
套路撩心 2024-07-14 17:24:29

http://ora-01775.ora-code.com/ 建议:

ORA-01775: 同义词循环链
原因:通过一系列 CREATE 同义词语句,定义了一个引用自身的同义词。 例如,以下定义是循环的:
为 s2 创建同义词 s1 为 s3 创建同义词 s2 为 s1 创建同义词 s3
操作:更改一个同义词定义,以便将其应用于基表或视图,然后重试该操作。

http://ora-01775.ora-code.com/ suggests:

ORA-01775: looping chain of synonyms
Cause: Through a series of CREATE synonym statements, a synonym was defined that referred to itself. For example, the following definitions are circular:
CREATE SYNONYM s1 for s2 CREATE SYNONYM s2 for s3 CREATE SYNONYM s3 for s1
Action: Change one synonym definition so that it applies to a base table or view and retry the operation.

狼性发作 2024-07-14 17:24:29

如果您正在编译一个 PROCEDURE,则这可能引用了一个在同一 PROCEDURE 中创建时不存在的表或视图。 在这种情况下,解决方案是将查询声明为字符串,例如 v_query: = 'insert into table select * from table2 ,然后立即执行 v_query;

这是因为编译器尚未识别该对象,因此找不到引用。 问候。

If you are compiling a PROCEDURE, possibly this is referring to a table or view that does not exist as it is created in the same PROCEDURE. In this case the solution is to make the query declared as String eg v_query: = 'insert into table select * from table2 and then execute immediate on v_query;

This is because the compiler does not yet recognize the object and therefore does not find the reference. Greetings.

无力看清 2024-07-14 17:24:29

我在错误的架构中定义了一个函数,并且没有公共同义词。 即我的过程位于模式“Dogs”中,函数位于模式“Cats”中。 该函数没有公共同义词来允许狗访问猫的函数。

I had a function defined in the wrong schema and without a public synonym. I.e. my proc was in schema "Dogs" and the function was in schema "Cats". The function didn't have a public synonym on it to allow Dogs to access the cats' function.

红ご颜醉 2024-07-14 17:24:29

对我来说,表名和同义词都存在,但所有者名称不同。 我在所有者名称下重新创建了与同义词中的所有者名称相匹配的表。

我使用了@Mahi_0707 发布的查询

For me, the table name and the synonym both existed but under different owner names. I re-created the tables under the owner name that matched the owner name in synonyms.

I used the queries posted by @Mahi_0707

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文